Problem running ruby script with rails42

This very simple script was running in 4.1.6

require ‘.\config\config.rb’
require ‘.\models\transazioni.rb’

Transazioni.where(isprocessed: ‘N’).each do |tr|
puts tr.id_transazione + ’ ’ + tr.transdate.to_s + ’ ’ +
tr.idmaximo.to_s +
’ ’ + tr.codsap
end

exit

database.yml:

DATA SOURCE

datasource:
adapter: oracle_enhanced
url: jdbc:oracle:thin:@x.x.x.x:1521:xxxx
username: xxx
password: xxx

config.rb:

require ‘rubygems’
require ‘active_record’
require ‘yaml’
require ‘logger’
require ‘C:/jrails4/jruby/lib/ojdbc6.jar’

@config_db = YAML::load(File.open(“config/database.yml”))
$src_db = @config_db[“datasource”]

Now with 4.2.0 I got this error:

C:/jrails4_update/jruby/lib/ruby/gems/shared/gems/activesupport-4.2.0/lib/active_support/dependencies.rb:587
warning: already initialized constant Reference
C:/jrails4_update/jruby/lib/ruby/gems/shared/gems/activesupport-4.2.0/lib/active_support/values/time_zone.rb:37
warning: already initialized constant MAPPING
C:/jrails4_update/jruby/lib/ruby/gems/shared/gems/activesupport-4.2.0/lib/active_support/values/time_zone.rb:186
warning: already initialized constant UTC_OFFSET_WITH_COLON
C:/jrails4_update/jruby/lib/ruby/gems/shared/gems/activesupport-4.2.0/lib/active_support/values/time_zone.rb:187
warning: already initialized constant UTC_OFFSET_WITHOUT_COLON
C:/jrails4_update/jruby/lib/ruby/gems/shared/gems/activerecord-4.2.0/lib/active_record/relation/delegation.rb:40
warning: already initialized constant BLACKLISTED_ARRAY_METHODS
ActiveSupport::Concern::MultipleIncludedBlocks: Cannot define multiple
‘included’ blocks for a Concern
included at
C:/jrails4_update/jruby/lib/ruby/gems/shared/gems/activesupport-4.2.0/lib/active_support/concern.rb:126
ClassSpecificRelation at
C:/jrails4_update/jruby/lib/ruby/gems/shared/gems/activerecord-4.2.0/lib/active_record/relation/delegation.rb:54
Delegation at
C:/jrails4_update/jruby/lib/ruby/gems/shared/gems/activerecord-4.2.0/lib/active_record/relation/delegation.rb:51
ActiveRecord at
C:/jrails4_update/jruby/lib/ruby/gems/shared/gems/activerecord-4.2.0/lib/active_record/relation/delegation.rb:6
(root) at
C:/jrails4_update/jruby/lib/ruby/gems/shared/gems/activerecord-4.2.0/lib/active_record/relation/delegation.rb:5
require at org/jruby/RubyKernel.java:1071
require at
C:/jrails4_update/jruby/lib/ruby/shared/rubygems/core_ext/kernel_require.rb:69
require at
C:/jrails4_update/jruby/lib/ruby/gems/shared/gems/activesupport-4.2.0/lib/active_support/dependencies.rb:274
load_dependency at
C:/jrails4_update/jruby/lib/ruby/gems/shared/gems/activesupport-4.2.0/lib/active_support/dependencies.rb:240
require at
C:/jrails4_update/jruby/lib/ruby/gems/shared/gems/activesupport-4.2.0/lib/active_support/dependencies.rb:274
(root) at
C:/jrails4_update/jruby/lib/ruby/gems/shared/gems/activerecord-4.2.0/lib/active_record/base.rb:1
(root) at
C:/jrails4_update/jruby/lib/ruby/gems/shared/gems/activerecord-4.2.0/lib/active_record/base.rb:23
require at org/jruby/RubyKernel.java:1071
require at
C:/jrails4_update/jruby/lib/ruby/shared/rubygems/core_ext/kernel_require.rb:121
(root) at transcont.rb:4

Do I have to modify something or it’s a bug?

Tnx
Fabio

P.S.

transazioni.rb (model)

class Transazioni < ActiveRecord::Base
self.table_name = ‘TRANSAZIONI_CONTABILI’
establish_connection($src_db)
end

My guess would be that something is getting loaded twice. I suggest
taking out all the requires and putting them back till you get the
problem. That may help you to home in on it.

Yes, it seems some constant is already initialized.

I tried removing the includes, but they are all needed…

On 30 January 2015 at 16:43, PandaR1 [email protected] wrote:

exit

@config_db = YAML::load(File.open(“config/database.yml”))
$src_db = @config_db[“datasource”]

Now with 4.2.0 I got this error:

C:/jrails4_update/jruby/lib/ruby/gems/shared/gems/activesupport-4.2.0/lib/active_support/dependencies.rb:587

warning: already initialized constant Reference

My guess would be that something is getting loaded twice. I suggest
taking out all the requires and putting them back till you get the
problem. That may help you to home in on it.

Colin

On 2 February 2015 at 10:17, PandaR1 [email protected] wrote:

My guess would be that something is getting loaded twice. I suggest
taking out all the requires and putting them back till you get the
problem. That may help you to home in on it.

Yes, it seems some constant is already initialized.

I tried removing the includes, but they are all needed…

The point is which is the one you add that causes this particular
error to occur? Once you find that then leave it in and take the
others out, then add them back in one at a time to find out which is
the one that adds the second initialisation.

Colin

The point is which is the one you add that causes this particular
error to occur? Once you find that then leave it in and take the
others out, then add them back in one at a time to find out which is
the one that adds the second initialisation.

I can remove require ‘rubygems’

But if I remove the next require line which requires activerecord then I
got a name error which says that active record is not defined

Same thing if I remove require yaml… and if I require active record
and
yaml then the error arise, even if I don’t require logger…

The natural way to run a script in a Rails environment is to use the
runner
command.

  1. Remove manual requires.

  2. bin/rails runner my_script.rb

Il giorno lunedì 2 febbraio 2015 14:14:02 UTC+1, Xavier N. ha
scritto:

The natural way to run a script in a Rails environment is to use the
runner command.

  1. Remove manual requires.

  2. bin/rails runner my_script.rb

does not seems to work under jruby… rails batch seems to not support
the
runner option…

On Fri, Jan 30, 2015 at 8:43 AM, PandaR1 [email protected]
wrote:

Now with 4.2.0 I got this error:

Do I have to modify something or it’s a bug?

See: Loading some constants twice with Rails 4.2.0.rc1 and postgres · Issue #2286 · jruby/jruby · GitHub

I suspect that’s your issue.

HTH!

Hassan S. ------------------------ [email protected]

twitter: @hassan
Consulting Availability : Silicon Valley or remote

Did you find out how to fix this?

Il giorno lunedì 2 febbraio 2015 19:39:31 UTC+1, Hassan S. ha
scritto:

I suspect that’s your issue.

Thanks, it also seems to me… I’ll wait for an updated adapter…