class OrchestratorClient::Job

Constants

DONE_EVENTS
DONE_STATES

Attributes

job_id[RW]
job_name[RW]
options[RW]

Public Class Methods

new(client, options = {}, type=:deploy) click to toggle source
# File lib/orchestrator_client/job.rb, line 17
def initialize(client, options = {}, type=:deploy)
  @client = client
  @poll_interval = options.delete(:_poll_interval) || client.config['job-poll-interval']
  @poll_timeout = options.delete(:_poll_timeout) || client.config['job-poll-timeout']
  @options = options
  @type = type
end

Public Instance Methods

assert_started?() click to toggle source
# File lib/orchestrator_client/job.rb, line 47
def assert_started?
  Raise ArgumentError "Job is not yet started" unless @job_name
end
details() click to toggle source
# File lib/orchestrator_client/job.rb, line 56
def details
  @details ||= get_details
end
each_event() { |event| ... } click to toggle source

A poll the events endpoint yielding each event

# File lib/orchestrator_client/job.rb, line 69
def each_event
  finished = false
  start = nil
  while !finished
    events = @client.jobs.events(@job_name)
    start = events['next-events']['event']
    if events['items'].empty?
      sleep @poll_interval
    else
      events['items'].each do |event|
        finished = true if DONE_EVENTS.include?(event['type'])
        yield event
      end
    end
  end
end
get_details() click to toggle source
# File lib/orchestrator_client/job.rb, line 51
def get_details
  assert_started?
  @details = @client.jobs.details(@job_name)
end
nodes() click to toggle source
# File lib/orchestrator_client/job.rb, line 64
def nodes
  @client.jobs.nodes(@job_name)
end
report() click to toggle source
# File lib/orchestrator_client/job.rb, line 60
def report
  @client.jobs.report(@job_name)
end
start() click to toggle source
# File lib/orchestrator_client/job.rb, line 25
def start
  case @type
  when :deploy
    result = @client.command.deploy(options)
  when :task
    result = @client.command.task(options)
  when :plan_task
    result = @client.command.plan_task(options)
  end

  @job_name = result['job']['name']
  @job_id = result['job']['id']
  @next_event=nil
  @job_name
end
stop() click to toggle source
# File lib/orchestrator_client/job.rb, line 41
def stop
  unless job_name
    Raise ArgumentError "Job name not known to stop"
  end
end
validate_scope() click to toggle source
# File lib/orchestrator_client/job.rb, line 8
def validate_scope
  scope = @options['scope']
  if scope.empty
    Raise ArgumentError 'Scope cannot be empty'
  elif  scope['whole_environment']
    puts 'Deprecation Warning: Whole environment behavior may not be stable'
  end
end
wait(timeout=@poll_timeout) click to toggle source
# File lib/orchestrator_client/job.rb, line 86
def wait(timeout=@poll_timeout)
  counter = 0
  while counter < timeout
    get_details
    if DONE_STATES.include?(details['state'])
      return report
    end
    sleep @poll_interval
    counter += @poll_interval
  end
end