class Roby::Interface::Async::JobMonitor
Asynchronous monitoring of a job
This is usually not created directly, but either by calling {Interface#on_job} or {Interface#find_all_jobs}. The jobs created by these two methods not listening for the job's progress, you must call {#start} on them to start tracking the job progress.
Then call {#stop} to remove the monitor.
Constants
- JOB_REACHABLE
Attributes
@return [Interface] the async interface we are bound to
@return [Integer] the job ID
@return [Roby::Task] the job's placeholder task
@return [Symbol] the job's current state
@return [Roby::Task] the job's main task
Public Class Methods
# File lib/roby/interface/async/job_monitor.rb, line 61 def initialize(interface, job_id, state: JOB_REACHABLE, task: nil, placeholder_task: task) @interface = interface @job_id = job_id @success = false @failed = false @has_ran = false @planning_finished = false update_state(state) @task = task @placeholder_task = placeholder_task end
Public Instance Methods
Returns the arguments that were passed to the action
# File lib/roby/interface/async/job_monitor.rb, line 102 def action_arguments task && task.action_arguments end
The job's action model
@return [Roby::Actions::Model::Action,nil]
# File lib/roby/interface/async/job_monitor.rb, line 90 def action_model task && task.action_model end
Returns the job's action name
@return [String,nil]
# File lib/roby/interface/async/job_monitor.rb, line 97 def action_name task && task.action_model.name end
Whether this job monitor is still active
# File lib/roby/interface/async/job_monitor.rb, line 185 def active? interface.active_job_monitor?(self) end
Send a command to drop this job
# File lib/roby/interface/async/job_monitor.rb, line 201 def drop interface.client.drop_job(job_id) end
Tests whether this job ran and failed
# File lib/roby/interface/async/job_monitor.rb, line 165 def failed? @failed end
Tests whether this job has been finalized
# File lib/roby/interface/async/job_monitor.rb, line 180 def finalized? Roby::Interface.finalized_state?(state) end
Tests whether this job ran and finished
# File lib/roby/interface/async/job_monitor.rb, line 170 def finished? @has_ran && terminated? end
@api private
# File lib/roby/interface/async/job_monitor.rb, line 116 def inspect "#<JobMonitor #{interface} job_id=#{job_id} state=#{state} task=#{task}>" end
Send a command to kill this job
# File lib/roby/interface/async/job_monitor.rb, line 206 def kill interface.client.kill_job(job_id) end
@api private
Triggers {#on_exception} and {#on_planning_failed} hooks
# File lib/roby/interface/async/job_monitor.rb, line 123 def notify_exception(kind, exception) if exception.exception.kind_of?(PlanningFailedError) if job_id = exception.exception.planning_task.arguments[:job_id] if job_id == self.job_id run_hook :on_planning_failed, kind, exception end end end run_hook :on_exception, kind, exception end
Tests whether planning finished
# File lib/roby/interface/async/job_monitor.rb, line 150 def planning_finished? @planning_finished end
@api private
Called when the placeholder task got replaced
@param [Roby::Task] new_task the new task
# File lib/roby/interface/async/job_monitor.rb, line 111 def replaced(new_task) @placeholder_task = new_task end
Kill this job and start an equivalent one
@return [JobMonitor] the monitor object for the new job. It is
not listening to the new job yet, call {#start} for that
# File lib/roby/interface/async/job_monitor.rb, line 77 def restart batch = interface.client.create_batch if !terminated? batch.kill_job(job_id) end batch.start_job(action_name, action_arguments) job_id = batch.__process.started_jobs_id.first interface.monitor_job(job_id) end
Tests whether this job is running
# File lib/roby/interface/async/job_monitor.rb, line 155 def running? Roby::Interface.running_state?(state) end
Start monitoring this job's state
# File lib/roby/interface/async/job_monitor.rb, line 190 def start update_state(state) interface.add_job_monitor(self) end
Stop monitoring this job's state
# File lib/roby/interface/async/job_monitor.rb, line 196 def stop interface.remove_job_monitor(self) end
Tests whether this job ran successfully
# File lib/roby/interface/async/job_monitor.rb, line 160 def success? @success end
Tests whether this job is terminated
# File lib/roby/interface/async/job_monitor.rb, line 175 def terminated? Roby::Interface.terminal_state?(state) end
@api private
Called by {Interface} to update the job's state
# File lib/roby/interface/async/job_monitor.rb, line 137 def update_state(state) @state = state if state != JOB_REACHABLE @planning_finished ||= Roby::Interface.planning_finished_state?(state) @success ||= Roby::Interface.success_state?(state) @failed ||= Roby::Interface.error_state?(state) @has_ran ||= (Roby::Interface.planning_finished_state?(state) && state != JOB_READY && state != JOB_PLANNING_FAILED) end run_hook :on_progress, state end