class Eco::API::Session::Batch::Jobs
Attributes
Public Class Methods
Eco::API::Common::Session::BaseSession::new
# File lib/eco/api/session/batch/jobs.rb, line 9 def initialize(e, name:) super(e) @name = name reset end
Public Instance Methods
# File lib/eco/api/session/batch/jobs.rb, line 37 def [](name) @jobs[name] end
@param job [Eco::API::Session::Batch::Job] the `Batch::Job` to add. @yield [job, status] callback after launching the batch job request against the server. @yieldparam job [Eco::API::Session::Batch::Job] the job we have launched against the server. @yieldparam status [Eco::API::Session::Batch::Status] the status of the batch job launch. @return [Eco::API::Session::Batch::Job]
# File lib/eco/api/session/batch/jobs.rb, line 75 def add(job) fatal "Expected Eco::API::Session::Batch::Job object. Given #{job.class}" unless job.is_a?(Eco::API::Session::Batch::Job) @jobs[job.name] = job @callbacks[job] = Proc.new if block_given? end
# File lib/eco/api/session/batch/jobs.rb, line 28 def each(&block) return to_enum(:each) unless block items.each(&block) end
# File lib/eco/api/session/batch/jobs.rb, line 24 def empty? count == 0 end
# File lib/eco/api/session/batch/jobs.rb, line 118 def errors? any? {|job| job.errors?} end
# File lib/eco/api/session/batch/jobs.rb, line 41 def exists?(name) @jobs.key?(name) end
# File lib/eco/api/session/batch/jobs.rb, line 101 def find_jobs(type:) each_with_object([]) do |job, jbs| jbs.push(job) if job.type == type end end
# File lib/eco/api/session/batch/jobs.rb, line 33 def items @jobs.values end
It retrieves an existing job named `name` or creates it if it doesn't exist. @note
- the block should only be passed when creating the job
@param [see @Eco::API::Session::Batch::Jobs#new] @return [Eco::API::Session::Batch::Job]
# File lib/eco/api/session/batch/jobs.rb, line 50 def job(name, type: nil, sets: nil, usecase: nil, &block) fatal "Can't give a job post-launch callback &block to an already existing job" if exists?(name) new(name, type: type, sets: sets, usecase: usecase, &block) unless exists?(name) self[name] end
Launches every `Batch::Job` in the group. @note
- if there was post-launch callback for a `Batch::Job`, it calls it.
@return [Hash<Eco::API::Session::Batch::Job, Eco::API::Session::Batch::Status>]
# File lib/eco/api/session/batch/jobs.rb, line 89 def launch(simulate: false) each do |job| if job.pending? status[job] = job_status = job.launch(simulate: simulate) callback = @callbacks[job] callback.call(job, job_status) if callback end end launch(simulate: simulate) if pending? return status end
# File lib/eco/api/session/batch/jobs.rb, line 20 def length count end
Creates a new `Batch::Job` included as part of this `Batch::Jobs`. @param [see Eco::API::Session::Job#new] @yield [job, status] callback after launching the batch job request against the server. @yieldparam job [Eco::API::Session::Batch::Job] the job we have launched against the server. @yieldparam status [Eco::API::Session::Batch::Status] the status of the batch job launch. @return [Eco::API::Session::Batch::Job]
# File lib/eco/api/session/batch/jobs.rb, line 62 def new(name, type:, sets:, usecase: nil, &block) fatal "Can't create job named '#{name}' because it already exists." if exists?(name) Batch::Job.new(enviro, name: name, type: type, sets: sets, usecase: usecase).tap do |job| add(job, &block) end end
# File lib/eco/api/session/batch/jobs.rb, line 81 def pending? any? {|job| job.pending?} end
# File lib/eco/api/session/batch/jobs.rb, line 15 def reset @jobs = {} @callbacks = {} end
# File lib/eco/api/session/batch/jobs.rb, line 107 def status if block_given? status.each do |job, job_status| yield(job, job_status) end self else @jobs_status ||= {} end end
# File lib/eco/api/session/batch/jobs.rb, line 122 def summary [].tap do |msg| map {|job| msg << job.summary} end.join("\n") end