Sha256: 178a573051b2170dfe23ee2529a61f6368f1a001f92a66a26db50b723f55fe92

Contents?: true

Size: 1.39 KB

Versions: 10

Compression:

Stored size: 1.39 KB

Contents

module Eco
  module API
    class Session
      class BatchJobs < API::Common::Session::BaseSession
        attr_reader :name, :session

        def initialize(name, session:)
          raise("BatchJobs requires a session object") unless session.is_a?(API::Session)
          super(session.enviro)
          @session = session
          @name     = name
          reset
        end

        def reset
          @jobs = {}
          @callbacks = {}
        end

        def [](name)
          @jobs[name]
        end

        def exists?(name)
          @jobs.key?(name)
        end

        def new(name, type:, sets:)
          raise("Can't create job named '#{name}' because it already exists.") if exists?(name)

          job = BatchJob.new(name, type: type, sets: sets, root: self)
          @jobs[name] = job
          @callbacks[job] = Proc.new if block_given?

          job
        end

        def pending?
          @jobs.keys.any? do |key|
            @jobs[key].pending?
          end
        end

        def launch(simulate: false)
          group_status = {}
          @jobs.each do |name, job|
            group_status[job] = job_status = job.launch(simulate: simulate)
            callback = @callbacks[job]
            callback.call(job, job_status) if callback
          end

          return group_status
        end

      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
eco-helpers-0.6.13 lib/eco/api/session/job_group.rb
eco-helpers-0.6.12 lib/eco/api/session/job_group.rb
eco-helpers-0.6.11 lib/eco/api/session/job_group.rb
eco-helpers-0.6.9 lib/eco/api/session/job_group.rb
eco-helpers-0.6.8 lib/eco/api/session/job_group.rb
eco-helpers-0.6.7 lib/eco/api/session/job_group.rb
eco-helpers-0.6.6 lib/eco/api/session/job_group.rb
eco-helpers-0.6.5 lib/eco/api/session/job_group.rb
eco-helpers-0.6.4 lib/eco/api/session/job_group.rb
eco-helpers-0.6.3 lib/eco/api/session/job_group.rb