Sha256: a27ea7534da28ca195ca9330540ef78e1c8a64e54442f42d579d54137455ddbb
Contents?: true
Size: 1.93 KB
Versions: 10
Compression:
Stored size: 1.93 KB
Contents
module Eco module API class Session class JobGroups < API::Common::Session::BaseSession DELAY_BETWEEN_GROUPS = 2 def initialize(session:) raise("JobGroups requires a session object") unless session.is_a?(API::Session) super(session.enviro) @session = session reset end def reset @order = [] @groups = {} @callbacks = {} end def [](name) @groups[name] end def exists?(name) @groups.key?(name) end def new(name, order: :last) raise("Can't create job group named #{'name'} because it already exists.") if exists?(name) group = BatchJobs.new(name, session: @session) @groups[name] = group if order == :last @order.push(group) else @order.unshift(group) end @callbacks[group] = Proc.new if block_given? group end def pending? @groups.any? do |group| group.pending? end end def launch(simulate: false) groups_status = {} @order.each.with_index do |group, idx| groups_status[group] = group_status = group.launch(simulate: simulate) callback = @callbacks[group] callback.call(group, group_status) if callback JobGroups.counter(DELAY_BETWEEN_GROUPS) if !simulate && idx < @order.length - 1 end return groups_status end def self.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 end end end end
Version data entries
10 entries across 10 versions & 1 rubygems