Class: OrchestratorClient::Job
- Inherits:
-
Object
- Object
- OrchestratorClient::Job
- Defined in:
- lib/orchestrator_client/job.rb
Constant Summary collapse
- DONE_STATES =
['stopped', 'finished', 'failed']
- DONE_EVENTS =
['job_aborted', 'job_finished']
Instance Attribute Summary collapse
-
#job_id ⇒ Object
Returns the value of attribute job_id.
-
#job_name ⇒ Object
Returns the value of attribute job_name.
-
#options ⇒ Object
Returns the value of attribute options.
Instance Method Summary collapse
- #assert_started? ⇒ Boolean
- #details ⇒ Object
-
#each_event ⇒ Object
A poll the events endpoint yielding each event.
- #get_details ⇒ Object
-
#initialize(client, options = {}, type = :deploy) ⇒ Job
constructor
A new instance of Job.
- #nodes ⇒ Object
- #report ⇒ Object
- #start ⇒ Object
- #stop ⇒ Object
- #validate_scope ⇒ Object
- #wait(timeout = 1000) ⇒ Object
Constructor Details
#initialize(client, options = {}, type = :deploy) ⇒ Job
Returns a new instance of Job.
17 18 19 20 21 |
# File 'lib/orchestrator_client/job.rb', line 17 def initialize(client, = {}, type=:deploy) @client = client = @type = type end |
Instance Attribute Details
#job_id ⇒ Object
Returns the value of attribute job_id.
6 7 8 |
# File 'lib/orchestrator_client/job.rb', line 6 def job_id @job_id end |
#job_name ⇒ Object
Returns the value of attribute job_name.
6 7 8 |
# File 'lib/orchestrator_client/job.rb', line 6 def job_name @job_name end |
#options ⇒ Object
Returns the value of attribute options.
6 7 8 |
# File 'lib/orchestrator_client/job.rb', line 6 def end |
Instance Method Details
#assert_started? ⇒ Boolean
45 46 47 |
# File 'lib/orchestrator_client/job.rb', line 45 def assert_started? Raise ArgumentError "Job is not yet started" unless @job_name end |
#details ⇒ Object
54 55 56 |
# File 'lib/orchestrator_client/job.rb', line 54 def details @details ||= get_details end |
#each_event ⇒ Object
A poll the events endpoint yielding each event
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/orchestrator_client/job.rb', line 67 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 1 else events['items'].each do |event| finished = true if DONE_EVENTS.include?(event['type']) yield event end end end end |
#get_details ⇒ Object
49 50 51 52 |
# File 'lib/orchestrator_client/job.rb', line 49 def get_details assert_started? @details = @client.jobs.details(@job_name) end |
#nodes ⇒ Object
62 63 64 |
# File 'lib/orchestrator_client/job.rb', line 62 def nodes @client.jobs.nodes(@job_name) end |
#report ⇒ Object
58 59 60 |
# File 'lib/orchestrator_client/job.rb', line 58 def report @client.jobs.report(@job_name) end |
#start ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/orchestrator_client/job.rb', line 23 def start case @type when :deploy result = @client.command.deploy() when :task result = @client.command.task() when :plan_task result = @client.command.plan_task() end @job_name = result['job']['name'] @job_id = result['job']['id'] @next_event=nil @job_name end |
#stop ⇒ Object
39 40 41 42 43 |
# File 'lib/orchestrator_client/job.rb', line 39 def stop unless job_name Raise ArgumentError "Job name not known to stop" end end |
#validate_scope ⇒ Object
8 9 10 11 12 13 14 15 |
# File 'lib/orchestrator_client/job.rb', line 8 def validate_scope scope = ['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 = 1000) ⇒ Object
84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/orchestrator_client/job.rb', line 84 def wait(timeout=1000) counter = 0 while counter < timeout get_details if DONE_STATES.include?(details['state']) return report end sleep 1 counter += 1 end end |