class Roby::Interface::Async::ActionMonitor
An action definition
While {JobMonitor} represents a running / instanciated job, this represents just an action with a set of argument. It binds automatically to a matching running job if there is one.
Attributes
The action name
The arguments that have been set to override the static arguments, or set arguments not yet set in {#static_arguments}
The underlying {JobMonitor} object if we're tracking a job
The underlying Async::Interface
The arguments that are part of the job definition itself
Public Class Methods
# File lib/roby/interface/async/action_monitor.rb, line 114 def initialize(interface, action_name, static_arguments = Hash.new) @interface, @action_name, @static_arguments = interface, action_name, static_arguments @arguments = Hash.new interface.on_reachable do run_hook :on_progress end interface.on_unreachable do unreachable! end interface.on_job(action_name: action_name) do |job| if !self.async || self.job_id != job.job_id || terminated? matching = static_arguments.all? do |arg_name, arg_val| job.action_arguments[arg_name.to_sym] == arg_val end if matching self.async = job job.start end end end end
Public Instance Methods
The set of arguments that should be passed to the action
It is basically the merged {#static_arguments} and {#arguments}
# File lib/roby/interface/async/action_monitor.rb, line 51 def action_arguments static_arguments.merge(arguments) end
# File lib/roby/interface/async/action_monitor.rb, line 175 def async=(async) @async = async async.on_progress do if self.async == async run_hook :on_progress end end run_hook :on_progress end
Drop this job
@param [Client::BatchContext] batch if given, the restart
commands will be added to this batch. Otherwise, a new batch is created and {Client::BatchContext#__process} is called.
# File lib/roby/interface/async/action_monitor.rb, line 73 def drop(batch: nil) handle_batch_argument(batch) do |b| b.drop_job(async.job_id) end end
Whether there is a job matching this action monitor running
# File lib/roby/interface/async/action_monitor.rb, line 33 def exists? !!async end
# File lib/roby/interface/async/action_monitor.rb, line 146 def failed? async && async.failed? end
# File lib/roby/interface/async/action_monitor.rb, line 150 def finished? async && async.finished? end
@api private
Helper to handle the batch argument in e.g. {#kill} and {#restart}
# File lib/roby/interface/async/action_monitor.rb, line 59 def handle_batch_argument(batch) if batch yield(batch) else yield(batch = interface.create_batch) batch.__process end end
The job ID of the last job that ran
# File lib/roby/interface/async/action_monitor.rb, line 43 def job_id async && async.job_id end
Kill this job
@param [Client::BatchContext] batch if given, the restart
commands will be added to this batch. Otherwise, a new batch is created and {Client::BatchContext#__process} is called.
# File lib/roby/interface/async/action_monitor.rb, line 84 def kill(batch: nil) if !running? raise InvalidState, "cannot kill a non-running action" end handle_batch_argument(batch) do |b| b.kill_job(async.job_id) end end
Start or restart a job based on this action
@param [Hash] arguments the arguments that should be used
instead of {#action_arguments}
@param [Client::BatchContext] batch if given, the restart
commands will be added to this batch. Otherwise, a new batch is created and {Client::BatchContext#__process} is called.
# File lib/roby/interface/async/action_monitor.rb, line 101 def restart(arguments = self.action_arguments, batch: nil, lazy: false) if lazy && running? && (arguments == async.action_arguments) return end handle_batch_argument(batch) do |b| if running? kill(batch: b) end b.start_job(action_name, arguments) end end
# File lib/roby/interface/async/action_monitor.rb, line 138 def running? async && async.running? end
# File lib/roby/interface/async/action_monitor.rb, line 158 def state if interface.reachable? if !async :reachable else async.state end else :unreachable end end
# File lib/roby/interface/async/action_monitor.rb, line 142 def success? async && async.success? end
If at least one job ran and is terminated
# File lib/roby/interface/async/action_monitor.rb, line 38 def terminated? async && async.terminated? end
# File lib/roby/interface/async/action_monitor.rb, line 170 def unreachable! @async = nil run_hook :on_progress end