0

rufus-scheduler gem과 salesforcebulk gem을 사용하여 레일스 데이터를 정기적으로 가져 오려고합니다.대량 API를 사용하여 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/[email protected]/gems/activerecord-3.2.13/lib/active_record/connection_adapters/sqlite_adapter.rb:208:in `encode' 
/Users/arturodiaz/.rvm/gems/[email protected]/gems/activerecord-3.2.13/lib/active_record/connection_adapters/sqlite_adapter.rb:208:in `type_cast' 
/Users/arturodiaz/.rvm/gems/[email protected]/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/[email protected]/gems/activerecord-3.2.13/lib/active_record/connection_adapters/sqlite_adapter.rb:258:in `map' 
/Users/arturodiaz/.rvm/gems/[email protected]/gems/activerecord-3.2.13/lib/active_record/connection_adapters/sqlite_adapter.rb:258:in `block in exec_query' 
/Users/arturodiaz/.rvm/gems/[email protected]/gems/activerecord-3.2.13/lib/active_record/connection_adapters/abstract_adapter.rb:280:in `block in log' 
/Users/arturodiaz/.rvm/gems/[email protected]/gems/activesupport-3.2.13/lib/active_support/notifications/instrumenter.rb:20:in `instrument' 
/Users/arturodiaz/.rvm/gems/[email protected]/gems/activerecord-3.2.13/lib/active_record/connection_adapters/abstract_adapter.rb:275:in `log' 
/Users/arturodiaz/.rvm/gems/[email protected]/gems/activerecord-3.2.13/lib/active_record/connection_adapters/sqlite_adapter.rb:242:in `exec_query' 
/Users/arturodiaz/.rvm/gems/[email protected]/gems/activerecord-3.2.13/lib/active_record/connection_adapters/abstract/database_statements.rb:63:in `exec_insert' 
/Users/arturodiaz/.rvm/gems/[email protected]/gems/activerecord-3.2.13/lib/active_record/connection_adapters/abstract/database_statements.rb:90:in `insert' 
/Users/arturodiaz/.rvm/gems/[email protected]/gems/activerecord-3.2.13/lib/active_record/connection_adapters/abstract/query_cache.rb:14:in `insert' 
/Users/arturodiaz/.rvm/gems/[email protected]/gems/activerecord-3.2.13/lib/active_record/relation.rb:66:in `insert' 
/Users/arturodiaz/.rvm/gems/[email protected]/gems/activerecord-3.2.13/lib/active_record/persistence.rb:367:in `create' 
/Users/arturodiaz/.rvm/gems/[email protected]/gems/activerecord-3.2.13/lib/active_record/timestamp.rb:58:in `create' 
/Users/arturodiaz/.rvm/gems/[email protected]/gems/activerecord-3.2.13/lib/active_record/callbacks.rb:268:in `block in create' 
/Users/arturodiaz/.rvm/gems/[email protected]/gems/activesupport-3.2.13/lib/active_support/callbacks.rb:403:in `_run__3666243914465906250__create__2439689705720496844__callbacks' 
/Users/arturodiaz/.rvm/gems/[email protected]/gems/activesupport-3.2.13/lib/active_support/callbacks.rb:405:in `__run_callback' 
/Users/arturodiaz/.rvm/gems/[email protected]/gems/activesupport-3.2.13/lib/active_support/callbacks.rb:385:in `_run_create_callbacks' 
/Users/arturodiaz/.rvm/gems/[email protected]/gems/activesupport-3.2.13/lib/active_support/callbacks.rb:81:in `run_callbacks' 
/Users/arturodiaz/.rvm/gems/[email protected]/gems/activerecord-3.2.13/lib/active_record/callbacks.rb:268:in `create' 
/Users/arturodiaz/.rvm/gems/[email protected]/gems/activerecord-3.2.13/lib/active_record/persistence.rb:348:in `create_or_update' 
/Users/arturodiaz/.rvm/gems/[email protected]/gems/activerecord-3.2.13/lib/active_record/callbacks.rb:264:in `block in create_or_update' 
/Users/arturodiaz/.rvm/gems/[email protected]/gems/activesupport-3.2.13/lib/active_support/callbacks.rb:414:in `_run__3666243914465906250__save__2439689705720496844__callbacks' 
/Users/arturodiaz/.rvm/gems/[email protected]/gems/activesupport-3.2.13/lib/active_support/callbacks.rb:405:in `__run_callback' 
/Users/arturodiaz/.rvm/gems/[email protected]/gems/activesupport-3.2.13/lib/active_support/callbacks.rb:385:in `_run_save_callbacks' 
/Users/arturodiaz/.rvm/gems/[email protected]/gems/activesupport-3.2.13/lib/active_support/callbacks.rb:81:in `run_callbacks' 
/Users/arturodiaz/.rvm/gems/[email protected]/gems/activerecord-3.2.13/lib/active_record/callbacks.rb:264:in `create_or_update' 
/Users/arturodiaz/.rvm/gems/[email protected]/gems/activerecord-3.2.13/lib/active_record/persistence.rb:84:in `save' 
/Users/arturodiaz/.rvm/gems/[email protected]/gems/activerecord-3.2.13/lib/active_record/validations.rb:50:in `save' 
/Users/arturodiaz/.rvm/gems/[email protected]/gems/activerecord-3.2.13/lib/active_record/attribute_methods/dirty.rb:22:in `save' 
/Users/arturodiaz/.rvm/gems/[email protected]/gems/activerecord-3.2.13/lib/active_record/transactions.rb:259:in `block (2 levels) in save' 
/Users/arturodiaz/.rvm/gems/[email protected]/gems/activerecord-3.2.13/lib/active_record/transactions.rb:313:in `block in with_transaction_returning_status' 
/Users/arturodiaz/.rvm/gems/[email protected]/gems/activerecord-3.2.13/lib/active_record/connection_adapters/abstract/database_statements.rb:192:in `transaction' 
/Users/arturodiaz/.rvm/gems/[email protected]/gems/activerecord-3.2.13/lib/active_record/transactions.rb:208:in `transaction' 
/Users/arturodiaz/.rvm/gems/[email protected]/gems/activerecord-3.2.13/lib/active_record/transactions.rb:311:in `with_transaction_returning_status' 
/Users/arturodiaz/.rvm/gems/[email protected]/gems/activerecord-3.2.13/lib/active_record/transactions.rb:259:in `block in save' 
/Users/arturodiaz/.rvm/gems/[email protected]/gems/activerecord-3.2.13/lib/active_record/transactions.rb:270:in `rollback_active_record_state!' 
/Users/arturodiaz/.rvm/gems/[email protected]/gems/activerecord-3.2.13/lib/active_record/transactions.rb:258:in `save' 
/Users/arturodiaz/.rvm/gems/[email protected]/gems/activerecord-3.2.13/lib/active_record/relation/finder_methods.rb:296:in `find_or_instantiator_by_attributes' 
/Users/arturodiaz/.rvm/gems/[email protected]/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/[email protected]/gems/rufus-scheduler-2.0.19/lib/rufus/sc/jobs.rb:231:in `call' 
/Users/arturodiaz/.rvm/gems/[email protected]/gems/rufus-scheduler-2.0.19/lib/rufus/sc/jobs.rb:231:in `trigger_block' 
/Users/arturodiaz/.rvm/gems/[email protected]/gems/rufus-scheduler-2.0.19/lib/rufus/sc/jobs.rb:191:in `block in trigger' 
/Users/arturodiaz/.rvm/gems/[email protected]/gems/rufus-scheduler-2.0.19/lib/rufus/sc/scheduler.rb:415:in `call' 
/Users/arturodiaz/.rvm/gems/[email protected]/gems/rufus-scheduler-2.0.19/lib/rufus/sc/scheduler.rb:415:in `block in trigger_job' 
================================================================================ 

성공적으로하고있는 객체의 코드 검색 및 수입 :

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 
: 여기
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 

은 비 작동 코드

나는 이미 salesforcebulk 보석의 batch_result 메소드 안에있는 CSV 파서의 인코딩을 성공하지 않고 변경하려고했습니다.

하나의 코드가 작동하고 다른 코드는 작동하지 않는다는 것이 매우 이상합니다. 아마도 그것은 특정 테이블에 관한 것입니다.

답변

0

당신은 오류에 초점을 맞추어야한다 :이 이름 열에 (라페에서와 같은) ~ N 것으로 보인다 및 SQLite는 어댑터를 좋아하지 않는

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

/Users/arturodiaz/.rvm/gems/[email protected]/gems/ 
activerecord-3.2.13/lib/active_record/connection_adapters/ 
sqlite_adapter.rb:208:in `encode' 

. 아마도 Salesforce 대량 보석에는 일종의 현지화 설정이 필요합니다.

이것은 rufus-scheduler와는 아무런 관련이 없습니다.