Class: Seiun::Job
- Inherits:
-
Object
- Object
- Seiun::Job
- Defined in:
- lib/seiun/job.rb
Defined Under Namespace
Classes: Batch
Instance Attribute Summary collapse
-
#id ⇒ Object
readonly
Returns the value of attribute id.
Instance Method Summary collapse
- #add_batch(records) ⇒ Object
- #add_query(soql) ⇒ Object
- #batches(get: true) ⇒ Object
- #closed? ⇒ Boolean
- #each_result ⇒ Object
- #get_results ⇒ Object
-
#initialize(connection, operation: nil, object_name: nil, id: nil, ext_field_name: nil, callback: nil) ⇒ Job
constructor
A new instance of Job.
- #object_name(get: true) ⇒ Object
- #operation(get: true) ⇒ Object
- #post_closing ⇒ Object
- #post_creation ⇒ Object
- #sf_state(get: true) ⇒ Object
- #wait_finish ⇒ Object
Constructor Details
#initialize(connection, operation: nil, object_name: nil, id: nil, ext_field_name: nil, callback: nil) ⇒ Job
Returns a new instance of Job.
8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/seiun/job.rb', line 8 def initialize(connection, operation: nil, object_name: nil, id: nil, ext_field_name: nil, callback: nil) @connection = connection @operation = operation.to_sym if operation @object_name = object_name.to_s if object_name @id = id @ext_field_name = ext_field_name if callback callback.job = self @callback = callback end @batches = [] end |
Instance Attribute Details
#id ⇒ Object (readonly)
Returns the value of attribute id.
6 7 8 |
# File 'lib/seiun/job.rb', line 6 def id @id end |
Instance Method Details
#add_batch(records) ⇒ Object
38 39 40 41 |
# File 'lib/seiun/job.rb', line 38 def add_batch(records) response_body = @connection.add_batch(add_batch_xml(records), @id, callback: @callback) parse_batch_xml(response_body) end |
#add_query(soql) ⇒ Object
33 34 35 36 |
# File 'lib/seiun/job.rb', line 33 def add_query(soql) response_body = @connection.add_query(soql, @id, callback: @callback) parse_batch_xml(response_body) end |
#batches(get: true) ⇒ Object
84 85 86 87 88 |
# File 'lib/seiun/job.rb', line 84 def batches(get: true) return @batches if !@batches.empty? || get == false get_batch_details @batches end |
#closed? ⇒ Boolean
103 104 105 |
# File 'lib/seiun/job.rb', line 103 def closed? sf_state == "Closed" end |
#each_result ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/seiun/job.rb', line 43 def each_result wait_finish batches.each do |batch| result_response_body = @connection.get_result(@id, batch.id, callback: @callback) Seiun::XMLParsers::ResultXML.each(result_response_body) do |result_response| if query? response_body = @connection.get_query_result(@id, batch.id, result_response.result_id, callback: @callback) Seiun::XMLParsers::RecordXML.each(response_body) do |response| yield(response.to_hash) end else yield(result_response.to_hash) end end end end |
#get_results ⇒ Object
60 61 62 63 64 |
# File 'lib/seiun/job.rb', line 60 def get_results results = [] each_result{|res| results << res } results end |
#object_name(get: true) ⇒ Object
66 67 68 69 70 |
# File 'lib/seiun/job.rb', line 66 def object_name(get: true) return @object_name if @object_name || get == false get_job_details @object_name end |
#operation(get: true) ⇒ Object
72 73 74 75 76 |
# File 'lib/seiun/job.rb', line 72 def operation(get: true) return @operation if @operation || get == false get_job_details @operation end |
#post_closing ⇒ Object
27 28 29 30 31 |
# File 'lib/seiun/job.rb', line 27 def post_closing response_body = @connection.close_job(close_job_xml, @id, callback: @callback) parse_job_xml(response_body) @callback.after_close_job(self) if @callback end |
#post_creation ⇒ Object
21 22 23 24 25 |
# File 'lib/seiun/job.rb', line 21 def post_creation response_body = @connection.create_job(create_job_xml, callback: @callback) parse_job_xml(response_body) @callback.after_create_job(self) if @callback end |
#sf_state(get: true) ⇒ Object
78 79 80 81 82 |
# File 'lib/seiun/job.rb', line 78 def sf_state(get: true) return @sf_state if @sf_state || get == false get_job_details @sf_state end |
#wait_finish ⇒ Object
90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/seiun/job.rb', line 90 def wait_finish Timeout.timeout(sec_to_wait_finish) do until closed? get_job_details sleep 1 end until all_batch_finished? get_batch_details sleep 1 end end end |