Sha256: 974c7e5148596dfe0b177cd2025d6eaee64c516c541dfa11a31acfb5466f60c6

Contents?: true

Size: 1.8 KB

Versions: 8

Compression:

Stored size: 1.8 KB

Contents

module Eco
  module API
    class Session
      class JobGroups < API::Common::Session::BaseSession
        DELAY_BETWEEN_GROUPS = 2

        def initialize(e)
          super(e)
          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)
          fatal "Can't create job group named '#{name}' because it already exists." if exists?(name)

          BatchJobs.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

        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

8 entries across 8 versions & 1 rubygems

Version Path
eco-helpers-0.9.2 lib/eco/api/session/job_groups.rb
eco-helpers-0.9.1 lib/eco/api/session/job_groups.rb
eco-helpers-0.8.4 lib/eco/api/session/job_groups.rb
eco-helpers-0.8.3 lib/eco/api/session/job_groups.rb
eco-helpers-0.8.2 lib/eco/api/session/job_groups.rb
eco-helpers-0.8.1 lib/eco/api/session/job_groups.rb
eco-helpers-0.7.2 lib/eco/api/session/job_groups.rb
eco-helpers-0.7.1 lib/eco/api/session/job_groups.rb