ปัญหาการเข้ารหัสเมื่อนำเข้าข้อมูล Salesforce ไปยัง Rails ด้วย Bulk Api

ฉันกำลังพยายามนำเข้าข้อมูลไปยัง Rail เป็นประจำโดยใช้ rufus-scheduler gem และ salesforcebulk gem

ฉันประสบความสำเร็จในการนำเข้าข้อมูลจากออบเจ็กต์แบบกำหนดเองของ Salesforce หนึ่งรายการไปยังฐานข้อมูลของฉัน แต่เมื่อฉันพยายามนำเข้าออบเจ็กต์อื่น ฉันพบปัญหา:

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'
================================================================================

นี่คือรหัสของออบเจ็กต์ที่ดึงและนำเข้าได้สำเร็จ:

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

นี่คือรหัสที่ไม่ทำงาน:

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

ฉันได้ลองเปลี่ยนการเข้ารหัสในตัวแยกวิเคราะห์ CSV ภายในวิธี batt_result ของ salesforcebulk gem แล้วโดยไม่ประสบความสำเร็จ

ฉันพบว่าแปลกมากที่โค้ดชิ้นหนึ่งใช้งานได้ แต่อีกชิ้นไม่ทำงาน บางทีมันอาจจะเกี่ยวกับตารางใดตารางหนึ่งก็ได้


person arturodz    schedule 03.07.2013    source แหล่งที่มา


คำตอบ (1)


คุณควรมุ่งเน้นไปที่ข้อผิดพลาด:

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'

ดูเหมือนว่าจะมี ~n (เช่นเดียวกับในJalapeño) ในคอลัมน์ชื่อของคุณและอะแดปเตอร์ sqlite ไม่ชอบมัน อาจเป็นไปได้ว่า Salesforce Bulk Gem ของคุณต้องใช้การตั้งค่าการแปลบางประเภท

สิ่งนี้ไม่เกี่ยวข้องกับ rufus-scheduler

person jmettraux    schedule 13.08.2013