Class: IronResponse::Batch
- Inherits:
-
Object
- Object
- IronResponse::Batch
- Defined in:
- lib/iron_response/batch.rb
Instance Attribute Summary collapse
-
#code ⇒ Object
Returns the value of attribute code.
-
#config ⇒ Object
Returns the value of attribute config.
-
#name ⇒ Object
Returns the value of attribute name.
-
#params_array ⇒ Object
Returns the value of attribute params_array.
-
#results ⇒ Object
Returns the value of attribute results.
Instance Method Summary collapse
- #create_code!(options = {}) ⇒ Object
- #get_aws_s3_response(task_id) ⇒ Object
- #get_iron_cache_response(task_id) ⇒ Object
- #get_response_from_task_id(task_id) ⇒ Object
-
#initialize(config) ⇒ Batch
constructor
A new instance of Batch.
- #patch_code!(options = {}) ⇒ Object
- #run! ⇒ Object
- #worker_name ⇒ Object
Constructor Details
#initialize(config) ⇒ Batch
Returns a new instance of Batch.
14 15 16 17 |
# File 'lib/iron_response/batch.rb', line 14 def initialize(config) @config = config @client = IronWorkerNG::Client.new(@config[:iron_io]) end |
Instance Attribute Details
#code ⇒ Object
Returns the value of attribute code.
12 13 14 |
# File 'lib/iron_response/batch.rb', line 12 def code @code end |
#config ⇒ Object
Returns the value of attribute config.
8 9 10 |
# File 'lib/iron_response/batch.rb', line 8 def config @config end |
#name ⇒ Object
Returns the value of attribute name.
9 10 11 |
# File 'lib/iron_response/batch.rb', line 9 def name @name end |
#params_array ⇒ Object
Returns the value of attribute params_array.
10 11 12 |
# File 'lib/iron_response/batch.rb', line 10 def params_array @params_array end |
#results ⇒ Object
Returns the value of attribute results.
11 12 13 |
# File 'lib/iron_response/batch.rb', line 11 def results @results end |
Instance Method Details
#create_code!(options = {}) ⇒ Object
72 73 74 75 |
# File 'lib/iron_response/batch.rb', line 72 def create_code!(={}) @code.merge_gem("iron_response", IronResponse::VERSION) if @code.runtime == "ruby" # bootstraps the current version with the worker @client.codes.create(@code, ) end |
#get_aws_s3_response(task_id) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/iron_response/batch.rb', line 44 def get_aws_s3_response(task_id) aws_s3 = @config[:aws_s3] AWS::S3::Base.establish_connection! access_key_id: aws_s3[:access_key_id], secret_access_key: aws_s3[:secret_access_key] bucket_name = IronResponse::Common.s3_bucket_name(@config) bucket = AWS::S3::Bucket.find(bucket_name) path = IronResponse::Common.s3_path(task_id) response = bucket[path] IronResponse::Common.handle_response(response, task_id, @client) end |
#get_iron_cache_response(task_id) ⇒ Object
57 58 59 60 61 62 63 64 65 66 |
# File 'lib/iron_response/batch.rb', line 57 def get_iron_cache_response(task_id) cache_client = IronCache::Client.new(@config[:iron_io]) cache_name = IronResponse::Common.iron_cache_cache_name(@config) cache = cache_client.cache(cache_name) key = IronResponse::Common.iron_cache_key(task_id) response = cache.get(key) IronResponse::Common.handle_response(response, task_id, @client) end |
#get_response_from_task_id(task_id) ⇒ Object
35 36 37 38 39 40 41 42 |
# File 'lib/iron_response/batch.rb', line 35 def get_response_from_task_id(task_id) case IronResponse::Common.response_provider(@config) when :iron_cache get_iron_cache_response(task_id) when :aws_s3 get_aws_s3_response(task_id) end end |
#patch_code!(options = {}) ⇒ Object
68 69 70 |
# File 'lib/iron_response/batch.rb', line 68 def patch_code!(={}) @client.codes.patch(@code, ) end |
#run! ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/iron_response/batch.rb', line 23 def run! task_ids = params_array.map do |params| params[:config] = @config @client.tasks.create(worker_name, params)._id end task_ids.map do |task_id| p "Fetching response for IronWorker task #{task_id}" get_response_from_task_id(@client.tasks.wait_for(task_id)._id) end end |
#worker_name ⇒ Object
19 20 21 |
# File 'lib/iron_response/batch.rb', line 19 def worker_name @code.name end |