0

I am trying to do regular imports of data to rails using rufus-scheduler gem and the salesforcebulk gem.

I've been successful in importing data from one salesforce custom object into my database but when I try to import other objects I run into trouble:

scheduler caught exception:
Encoding::UndefinedConversionError: "\xC3" from ASCII-8BIT to UTF-8: INSERT INTO "channels" ("created_at", "name", "updated_at") VALUES (?, ?, ?)
/Users/arturodiaz/.rvm/gems/ruby-2.0.0-p195@agripa/gems/activerecord-3.2.13/lib/active_record/connection_adapters/sqlite_adapter.rb:208:in `encode'
/Users/arturodiaz/.rvm/gems/ruby-2.0.0-p195@agripa/gems/activerecord-3.2.13/lib/active_record/connection_adapters/sqlite_adapter.rb:208:in `type_cast'
/Users/arturodiaz/.rvm/gems/ruby-2.0.0-p195@agripa/gems/activerecord-3.2.13/lib/active_record/connection_adapters/sqlite_adapter.rb:259:in `block (2 levels) in exec_query'
/Users/arturodiaz/.rvm/gems/ruby-2.0.0-p195@agripa/gems/activerecord-3.2.13/lib/active_record/connection_adapters/sqlite_adapter.rb:258:in `map'
/Users/arturodiaz/.rvm/gems/ruby-2.0.0-p195@agripa/gems/activerecord-3.2.13/lib/active_record/connection_adapters/sqlite_adapter.rb:258:in `block in exec_query'
/Users/arturodiaz/.rvm/gems/ruby-2.0.0-p195@agripa/gems/activerecord-3.2.13/lib/active_record/connection_adapters/abstract_adapter.rb:280:in `block in log'
/Users/arturodiaz/.rvm/gems/ruby-2.0.0-p195@agripa/gems/activesupport-3.2.13/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
/Users/arturodiaz/.rvm/gems/ruby-2.0.0-p195@agripa/gems/activerecord-3.2.13/lib/active_record/connection_adapters/abstract_adapter.rb:275:in `log'
/Users/arturodiaz/.rvm/gems/ruby-2.0.0-p195@agripa/gems/activerecord-3.2.13/lib/active_record/connection_adapters/sqlite_adapter.rb:242:in `exec_query'
/Users/arturodiaz/.rvm/gems/ruby-2.0.0-p195@agripa/gems/activerecord-3.2.13/lib/active_record/connection_adapters/abstract/database_statements.rb:63:in `exec_insert'
/Users/arturodiaz/.rvm/gems/ruby-2.0.0-p195@agripa/gems/activerecord-3.2.13/lib/active_record/connection_adapters/abstract/database_statements.rb:90:in `insert'
/Users/arturodiaz/.rvm/gems/ruby-2.0.0-p195@agripa/gems/activerecord-3.2.13/lib/active_record/connection_adapters/abstract/query_cache.rb:14:in `insert'
/Users/arturodiaz/.rvm/gems/ruby-2.0.0-p195@agripa/gems/activerecord-3.2.13/lib/active_record/relation.rb:66:in `insert'
/Users/arturodiaz/.rvm/gems/ruby-2.0.0-p195@agripa/gems/activerecord-3.2.13/lib/active_record/persistence.rb:367:in `create'
/Users/arturodiaz/.rvm/gems/ruby-2.0.0-p195@agripa/gems/activerecord-3.2.13/lib/active_record/timestamp.rb:58:in `create'
/Users/arturodiaz/.rvm/gems/ruby-2.0.0-p195@agripa/gems/activerecord-3.2.13/lib/active_record/callbacks.rb:268:in `block in create'
/Users/arturodiaz/.rvm/gems/ruby-2.0.0-p195@agripa/gems/activesupport-3.2.13/lib/active_support/callbacks.rb:403:in `_run__3666243914465906250__create__2439689705720496844__callbacks'
/Users/arturodiaz/.rvm/gems/ruby-2.0.0-p195@agripa/gems/activesupport-3.2.13/lib/active_support/callbacks.rb:405:in `__run_callback'
/Users/arturodiaz/.rvm/gems/ruby-2.0.0-p195@agripa/gems/activesupport-3.2.13/lib/active_support/callbacks.rb:385:in `_run_create_callbacks'
/Users/arturodiaz/.rvm/gems/ruby-2.0.0-p195@agripa/gems/activesupport-3.2.13/lib/active_support/callbacks.rb:81:in `run_callbacks'
/Users/arturodiaz/.rvm/gems/ruby-2.0.0-p195@agripa/gems/activerecord-3.2.13/lib/active_record/callbacks.rb:268:in `create'
/Users/arturodiaz/.rvm/gems/ruby-2.0.0-p195@agripa/gems/activerecord-3.2.13/lib/active_record/persistence.rb:348:in `create_or_update'
/Users/arturodiaz/.rvm/gems/ruby-2.0.0-p195@agripa/gems/activerecord-3.2.13/lib/active_record/callbacks.rb:264:in `block in create_or_update'
/Users/arturodiaz/.rvm/gems/ruby-2.0.0-p195@agripa/gems/activesupport-3.2.13/lib/active_support/callbacks.rb:414:in `_run__3666243914465906250__save__2439689705720496844__callbacks'
/Users/arturodiaz/.rvm/gems/ruby-2.0.0-p195@agripa/gems/activesupport-3.2.13/lib/active_support/callbacks.rb:405:in `__run_callback'
/Users/arturodiaz/.rvm/gems/ruby-2.0.0-p195@agripa/gems/activesupport-3.2.13/lib/active_support/callbacks.rb:385:in `_run_save_callbacks'
/Users/arturodiaz/.rvm/gems/ruby-2.0.0-p195@agripa/gems/activesupport-3.2.13/lib/active_support/callbacks.rb:81:in `run_callbacks'
/Users/arturodiaz/.rvm/gems/ruby-2.0.0-p195@agripa/gems/activerecord-3.2.13/lib/active_record/callbacks.rb:264:in `create_or_update'
/Users/arturodiaz/.rvm/gems/ruby-2.0.0-p195@agripa/gems/activerecord-3.2.13/lib/active_record/persistence.rb:84:in `save'
/Users/arturodiaz/.rvm/gems/ruby-2.0.0-p195@agripa/gems/activerecord-3.2.13/lib/active_record/validations.rb:50:in `save'
/Users/arturodiaz/.rvm/gems/ruby-2.0.0-p195@agripa/gems/activerecord-3.2.13/lib/active_record/attribute_methods/dirty.rb:22:in `save'
/Users/arturodiaz/.rvm/gems/ruby-2.0.0-p195@agripa/gems/activerecord-3.2.13/lib/active_record/transactions.rb:259:in `block (2 levels) in save'
/Users/arturodiaz/.rvm/gems/ruby-2.0.0-p195@agripa/gems/activerecord-3.2.13/lib/active_record/transactions.rb:313:in `block in with_transaction_returning_status'
/Users/arturodiaz/.rvm/gems/ruby-2.0.0-p195@agripa/gems/activerecord-3.2.13/lib/active_record/connection_adapters/abstract/database_statements.rb:192:in `transaction'
/Users/arturodiaz/.rvm/gems/ruby-2.0.0-p195@agripa/gems/activerecord-3.2.13/lib/active_record/transactions.rb:208:in `transaction'
/Users/arturodiaz/.rvm/gems/ruby-2.0.0-p195@agripa/gems/activerecord-3.2.13/lib/active_record/transactions.rb:311:in `with_transaction_returning_status'
/Users/arturodiaz/.rvm/gems/ruby-2.0.0-p195@agripa/gems/activerecord-3.2.13/lib/active_record/transactions.rb:259:in `block in save'
/Users/arturodiaz/.rvm/gems/ruby-2.0.0-p195@agripa/gems/activerecord-3.2.13/lib/active_record/transactions.rb:270:in `rollback_active_record_state!'
/Users/arturodiaz/.rvm/gems/ruby-2.0.0-p195@agripa/gems/activerecord-3.2.13/lib/active_record/transactions.rb:258:in `save'
/Users/arturodiaz/.rvm/gems/ruby-2.0.0-p195@agripa/gems/activerecord-3.2.13/lib/active_record/relation/finder_methods.rb:296:in `find_or_instantiator_by_attributes'
/Users/arturodiaz/.rvm/gems/ruby-2.0.0-p195@agripa/gems/activerecord-3.2.13/lib/active_record/dynamic_matchers.rb:52:in `method_missing'
/Users/arturodiaz/Drive/Code/partnerportal2/agripa/config/initializers/task_scheduler.rb:121:in `block (2 levels) in <top (required)>'
/Users/arturodiaz/Drive/Code/partnerportal2/agripa/config/initializers/task_scheduler.rb:120:in `each'
/Users/arturodiaz/Drive/Code/partnerportal2/agripa/config/initializers/task_scheduler.rb:120:in `block in <top (required)>'
/Users/arturodiaz/.rvm/gems/ruby-2.0.0-p195@agripa/gems/rufus-scheduler-2.0.19/lib/rufus/sc/jobs.rb:231:in `call'
/Users/arturodiaz/.rvm/gems/ruby-2.0.0-p195@agripa/gems/rufus-scheduler-2.0.19/lib/rufus/sc/jobs.rb:231:in `trigger_block'
/Users/arturodiaz/.rvm/gems/ruby-2.0.0-p195@agripa/gems/rufus-scheduler-2.0.19/lib/rufus/sc/jobs.rb:191:in `block in trigger'
/Users/arturodiaz/.rvm/gems/ruby-2.0.0-p195@agripa/gems/rufus-scheduler-2.0.19/lib/rufus/sc/scheduler.rb:415:in `call'
/Users/arturodiaz/.rvm/gems/ruby-2.0.0-p195@agripa/gems/rufus-scheduler-2.0.19/lib/rufus/sc/scheduler.rb:415:in `block in trigger_job'
================================================================================

Here is the code of the object which is successfully retrieved and imported:

scheduler.at("2013-07-03 11:17:15 -0700 ") do

  client = SalesforceBulk::Client.new(username: 'XXXXXXXXX', password: 'XXXXXXXXX')
  client.authenticate

  job = client.add_job(:query, :Paquete__c)

  batch = client.add_batch(job.id, "SELECT Id, Name, Capacidad__c, Organizacion__c FROM Paquete__c")

  job = client.close_job(job.id)

  sleep 5.0

  batch = client.batch_info(job.id, batch.id)

  results = client.batch_result(job.id, batch.id)

  results.each do |d|
    Paquete.find_or_create_by_serie_and_id_and_version(id: d[:Id],
                                                            serie: d[:Name],
                                                            account_id: d[:Organizacion__c],
                                                            capacidad: d[:Capacidad__c])
  end

  puts "Done... Paquetes"

end

Here is the non-working code:

scheduler.at("2013-07-03 11:40:00 -0700 ") do

client = SalesforceBulk::Client.new(username: 'XXXXXXXXXXXX', password: 'XXXXXXXXXXX')
client.authenticate

job = client.add_job(:query, :Account)

batch = client.add_batch(job.id, "SELECT Id, Name, Type FROM Account")
job = client.close_job(job.id)

sleep 5.0

batch = client.batch_info(job.id, batch.id)

results = client.batch_result(job.id, batch.id)

results.each do |d|
Account.find_or_create_by_id_and_name(id: d[:Id], name: d[:Name],type: d[:Type])                                                                

end

puts "Done... Accounts"

end

I've already tried to change the encoding in the CSV parser inside the batch_result method of the salesforcebulk gem without success.

I find very strange that one piece of code is working and the other does not. Perhaps it is something regarding a particular table.

4

1 回答 1

0

You should focus on the error:

Encoding::UndefinedConversionError: "\xC3" from ASCII-8BIT to UTF-8:
INSERT INTO "channels" ("created_at", "name", "updated_at") VALUES (?, ?, ?)

/Users/arturodiaz/.rvm/gems/ruby-2.0.0-p195@agripa/gems/
activerecord-3.2.13/lib/active_record/connection_adapters/
sqlite_adapter.rb:208:in `encode'

There seems to be a ~n (as in Jalapeño) in your name column and the sqlite adapter does not like it. Probably your Salesforce bulk gem takes some kind of localization setting.

This has nothing to do with rufus-scheduler.

于 2013-08-13T03:59:45.133 回答