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

interface[R]

@return [Interface] the async interface we are bound to

job_id[R]

@return [Integer] the job ID

placeholder_task[R]

@return [Roby::Task] the job's placeholder task

state[R]

@return [Symbol] the job's current state

task[R]

@return [Roby::Task] the job's main task

Public Class Methods

new(interface, job_id, state: JOB_REACHABLE, task: nil, placeholder_task: task) click to toggle source
# 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

action_arguments() click to toggle source

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
action_model() click to toggle source

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
action_name() click to toggle source

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
active?() click to toggle source

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
drop() click to toggle source

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
failed?() click to toggle source

Tests whether this job ran and failed

# File lib/roby/interface/async/job_monitor.rb, line 165
def failed?
    @failed
end
finalized?() click to toggle source

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
finished?() click to toggle source

Tests whether this job ran and finished

# File lib/roby/interface/async/job_monitor.rb, line 170
def finished?
    @has_ran && terminated?
end
inspect() click to toggle source

@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
kill() click to toggle source

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
notify_exception(kind, exception) click to toggle source

@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
planning_finished?() click to toggle source

Tests whether planning finished

# File lib/roby/interface/async/job_monitor.rb, line 150
def planning_finished?
    @planning_finished
end
replaced(new_task) click to toggle source

@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
restart() click to toggle source

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
running?() click to toggle source

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() click to toggle source

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() click to toggle source

Stop monitoring this job's state

# File lib/roby/interface/async/job_monitor.rb, line 196
def stop
    interface.remove_job_monitor(self)
end
success?() click to toggle source

Tests whether this job ran successfully

# File lib/roby/interface/async/job_monitor.rb, line 160
def success?
    @success
end
terminated?() click to toggle source

Tests whether this job is terminated

# File lib/roby/interface/async/job_monitor.rb, line 175
def terminated?
    Roby::Interface.terminal_state?(state)
end
update_state(state) click to toggle source

@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