Class: Bulkforce::Batch
- Inherits:
-
Object
- Object
- Bulkforce::Batch
- Defined in:
- lib/bulkforce/batch.rb
Instance Attribute Summary collapse
-
#job_id ⇒ Object
readonly
Returns the value of attribute job_id.
Instance Method Summary collapse
- #final_status(poll_interval = 2) ⇒ Object
-
#initialize(connection, job_id, batch_id) ⇒ Batch
constructor
A new instance of Batch.
- #raw_request ⇒ Object
- #raw_result ⇒ Object
-
#results ⇒ Object
results returned from Salesforce can be a single page id, or an array of ids.
- #status ⇒ Object
Constructor Details
#initialize(connection, job_id, batch_id) ⇒ Batch
Returns a new instance of Batch.
5 6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/bulkforce/batch.rb', line 5 def initialize connection, job_id, batch_id @connection = connection @job_id = job_id @batch_id = batch_id if @batch_id == -1 @final_status = { state: "Completed", state_message: "Empty Request" } end end |
Instance Attribute Details
#job_id ⇒ Object (readonly)
Returns the value of attribute job_id.
3 4 5 |
# File 'lib/bulkforce/batch.rb', line 3 def job_id @job_id end |
Instance Method Details
#final_status(poll_interval = 2) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/bulkforce/batch.rb', line 18 def final_status poll_interval=2 return @final_status if @final_status @final_status = self.status while ["Queued", "InProgress"].include?(@final_status[:state]) sleep poll_interval @final_status = self.status yield @final_status if block_given? end raise @final_status[:state_message] if @final_status[:state] == "Failed" @final_status.merge({ results: results }) end |
#raw_request ⇒ Object
53 54 55 |
# File 'lib/bulkforce/batch.rb', line 53 def raw_request @connection.raw_request end |
#raw_result ⇒ Object
57 58 59 |
# File 'lib/bulkforce/batch.rb', line 57 def raw_result @connection.raw_result end |
#results ⇒ Object
results returned from Salesforce can be a single page id, or an array of ids. if it“s an array of ids, we will fetch the results from each, and concatenate them.
41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/bulkforce/batch.rb', line 41 def results queried_result_id = query_result_id if queried_result_id Array(queried_result_id).map do |result_id| @connection.query_batch_result_data(@job_id, @batch_id, result_id) end.flatten else @connection.query_batch_result_id_csv(@job_id, @batch_id) end end |
#status ⇒ Object
35 36 37 |
# File 'lib/bulkforce/batch.rb', line 35 def status @connection.query_batch @job_id, @batch_id end |