Class Ruote::Worker
In: lib/ruote/worker.rb
Parent: Object

Workers fetch ‘msgs’ and ‘schedules’ from the storage and process them.

Read more at ruote.rubyforge.org/configuration.html

Methods

Classes and Modules

Class Ruote::Worker::Info

Constants

EXP_ACTIONS = %w[ reply cancel fail receive dispatched pause resume ]
PROC_ACTIONS = %w[ cancel kill pause resume ].collect { |a| a + '_process' }   ‘apply’ is comprised in ‘launch’ ‘receive’ is a ParticipantExpression alias for ‘reply‘
DISP_ACTIONS = %w[ dispatch dispatch_cancel dispatch_pause dispatch_resume ]

Attributes

context  [R] 
name  [R] 
run_thread  [R] 
state  [R] 
storage  [R] 

Public Class methods

Given a storage, creates a new instance of a Worker.

Public Instance methods

Returns true if the engine system is inactive, ie if all the process instances are terminated or are stuck in an error.

NOTE : for now, if a branch of a process is in error while another is still running, this method will consider the process instance inactive (and it will return true if all the processes are considered inactive).

Joins the run thread of this worker (if there is no such thread, this method will return immediately, without any effect).

Runs the worker in the current thread. See run_in_thread for running in a dedicated thread.

Triggers the run method of the worker in a dedicated thread.

Shuts down this worker (makes sure it won‘t fetch further messages and schedules).

Protected Instance methods

Some storage implementations cache information before a step begins, reducing the number of requests to the underlying data system. This begin step notifies the storage that a new step is on and it should refresh the cached information.

The storage implementation, if it supports this feature, will cache the information in the thread local info.

Handles a ‘cancel_process’ msg (translates it into a "cancel root expression of that process" msg).

Also works for ‘kill_process’ msgs.

If worker_state_enabled is set, check for a potential new state.

This default implementation dumps error information to $stderr as soon as step intercepts the error.

Normally such information should only appear when developing a storage, the information here is thus helpful for storage developers. If such info is emitted in production or in application development, you should pass the info to the storage developer/maintainer.

Feel free to override this method if you need it to output to a channel different than $stderr (or rebind $stderr).

The second parameter is "msg", if the error occured while processing a msg, then this message is passed to handle_step_error. msg will be nil if the error occurred while doing get_msgs or get_schedules.

Returns true if the msg is a "launch" (ie not a simply "apply").

kill_process(msg)

Alias for cancel_process

Works for both the ‘launch’ and the ‘apply’ msgs.

Creates a new expression, gives and applies it with the workitem contained in the msg.

Processes one msg.

Will return false immediately if the msg reservation failed (another worker grabbed the message.

Else will execute the action ordered in the msg, and return true.

Exceptions in execution are intercepted here and passed to the engine‘s (context‘s) error_handler.

Gets msgs from the storage (if needed) and processes them one by one.

Gets schedules from the storage and if their time has come, turns them into msg (for immediate execution).

Reputs a doc or a msg.

Used by certain storage implementations to pass documents around workers or to reschedule msgs (see ruote-swf).

This action resparks a stalled workflow instance. It‘s usually triggered via Dashboard#respark

It‘s been made into a msg (worker action) in order to facilitate migration tooling (ruote-swf for example).

resume_process(msg)

Alias for pause_process

One worker step, fetches schedules and triggers those whose time has came, then fetches msgs and processes them.

In order not to hammer the storage for msgs too much, take a rest.

If the number of processed messages is more than zero, there are probably more msgs coming, no time for a rest…

If @sleep_time is nil (restless_worker option set to true), the worker will never rest.

Given a schedule, attempts to trigger it.

It first tries to reserve the schedule. If the reservation fails (another worker was successful probably), false is returned. The schedule is triggered if the reservation was successful, true is returned.

[Validate]