class Eco::API::Session::Batch::JobsGroups
Constants
- DELAY_BETWEEN_GROUPS
Public Class Methods
counter(seconds)
click to toggle source
# File lib/eco/api/session/batch/jobs_groups.rb, line 9 def counter(seconds) puts "\n" while seconds + 1 > 0 do print " Waiting #{seconds}\r" $stdout.flush seconds -= 1 sleep 1 end print "#{" " * 40}" $stdout.flush puts "" end
new(e)
click to toggle source
Calls superclass method
Eco::API::Common::Session::BaseSession::new
# File lib/eco/api/session/batch/jobs_groups.rb, line 25 def initialize(e) super(e) reset end
Public Instance Methods
[](name)
click to toggle source
# File lib/eco/api/session/batch/jobs_groups.rb, line 53 def [](name) @groups[name] end
each(&block)
click to toggle source
# File lib/eco/api/session/batch/jobs_groups.rb, line 44 def each(&block) return to_enum(:each) unless block items.each(&block) end
empty?()
click to toggle source
# File lib/eco/api/session/batch/jobs_groups.rb, line 40 def empty? count == 0 end
errors?()
click to toggle source
# File lib/eco/api/session/batch/jobs_groups.rb, line 120 def errors? any? {|group| group.errors?} end
exists?(name)
click to toggle source
# File lib/eco/api/session/batch/jobs_groups.rb, line 57 def exists?(name) @groups.key?(name) end
find_jobs(type:)
click to toggle source
# File lib/eco/api/session/batch/jobs_groups.rb, line 103 def find_jobs(type:) each_with_object([]) do |group, jbs| jbs.concat(group.find_jobs(type: type)) end end
items()
click to toggle source
# File lib/eco/api/session/batch/jobs_groups.rb, line 49 def items @groups.values end
launch(simulate: false)
click to toggle source
Launches every `Batch::Jobs` group in the current `Batch::JobGroups` @note
- if there was post-launch callback for a `Batch::Jobs` groups, it calls it.
@return [Hash<Eco::API::Session::Batch::Jobs,Hash<Eco::API::Session::Batch::Job, Eco::API::Session::Batch::Status>>]
# File lib/eco/api/session/batch/jobs_groups.rb, line 90 def launch(simulate: false) @order.each_with_index do |group, idx| if group.pending? status[group] = group_status = group.launch(simulate: simulate) callback = @callbacks[group] callback.call(group, group_status) if callback self.class.counter(DELAY_BETWEEN_GROUPS) if !simulate && idx < @order.length - 1 end end launch(simulate: simulate) if pending? return status end
length()
click to toggle source
# File lib/eco/api/session/batch/jobs_groups.rb, line 36 def length count end
new(name, order: :last)
click to toggle source
Creates a new group of `Batch::Jobs` named `name`. @yield [group, group_status] callback after launching the batch job request against the server. @yieldparam group [Eco::API::Session::Batch::Jobs] the group of jobs we have launched against the server. @yieldparam group_status [Hash<Eco::API::Session::Batch::Job, Eco::API::Session::Batch::Status>] the status of the launched batch jobs. @return [Eco::API::Session::Batch::Jobs] the group of jobs.
# File lib/eco/api/session/batch/jobs_groups.rb, line 66 def new(name, order: :last) fatal "Can't create job group named '#{name}' because it already exists." if exists?(name) Batch::Jobs.new(enviro, name: name).tap do |group| @groups[name] = group if order == :last @order.push(group) else @order.unshift(group) end @callbacks[group] = Proc.new if block_given? end end
pending?()
click to toggle source
# File lib/eco/api/session/batch/jobs_groups.rb, line 82 def pending? any? {|group| group.pending?} end
reset()
click to toggle source
# File lib/eco/api/session/batch/jobs_groups.rb, line 30 def reset @order = [] @groups = {} @callbacks = {} end
status() { |group, group_status| ... }
click to toggle source
# File lib/eco/api/session/batch/jobs_groups.rb, line 109 def status if block_given? status.each do |group, group_status| yield(group, group_status) end self else @groups_status ||= {} end end
summary()
click to toggle source
# File lib/eco/api/session/batch/jobs_groups.rb, line 124 def summary [].tap do |msg| map {|group| msg << group.summary} end.join("\n") end