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 = @poll_timeout) ⇒ Object
Constructor Details
#initialize(client, options = {}, type = :deploy) ⇒ Job
Returns a new instance of Job.
17 18 19 20 21 22 23 |
# File 'lib/orchestrator_client/job.rb', line 17 def initialize(client, = {}, type=:deploy) @client = client @poll_interval = .delete(:_poll_interval) || client.config['job-poll-interval'] @poll_timeout = .delete(:_poll_timeout) || client.config['job-poll-timeout'] @options = @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 @options end |
Instance Method Details
#assert_started? ⇒ Boolean
47 48 49 |
# File 'lib/orchestrator_client/job.rb', line 47 def assert_started? Raise ArgumentError "Job is not yet started" unless @job_name end |
#details ⇒ Object
56 57 58 |
# File 'lib/orchestrator_client/job.rb', line 56 def details @details ||= get_details end |
#each_event ⇒ Object
A poll the events endpoint yielding each event
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# 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 ⇒ Object
51 52 53 54 |
# File 'lib/orchestrator_client/job.rb', line 51 def get_details assert_started? @details = @client.jobs.details(@job_name) end |
#nodes ⇒ Object
64 65 66 |
# File 'lib/orchestrator_client/job.rb', line 64 def nodes @client.jobs.nodes(@job_name) end |
#report ⇒ Object
60 61 62 |
# File 'lib/orchestrator_client/job.rb', line 60 def report @client.jobs.report(@job_name) end |
#start ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/orchestrator_client/job.rb', line 25 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
41 42 43 44 45 |
# 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 ⇒ Object
8 9 10 11 12 13 14 15 |
# 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) ⇒ Object
86 87 88 89 90 91 92 93 94 95 96 97 |
# 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 raise OrchestratorClient::JobWaitTimeout end |