RushWorker inherits all methods from Rush. Upon initialization, the worker registers itself in the Redis database as a running worker. This class is usually not constructed directly by the user.
In addition to the inherited methods, the worker provides methods that require a worker identity:
$pop_task(): Pop a task from the queue and mark it as running.$push_running_tasks(xss): Create running tasks evaluated by the worker.$finish_tasks(keys, yss): Save the output of tasks and mark them as finished.$fail_tasks(keys, conditions): Mark tasks as failed and optionally save the condition objects.
Value
Object of class R6::R6Class and RushWorker.
Super class
Rush -> RushWorker
Public fields
worker_id(
character(1))
Identifier of the worker.heartbeat(
callr::r_bg)
Background process for the heartbeat.
Active bindings
terminated(
logical(1))
Whether to shutdown the worker. Used in the worker loop to determine whether to continue.
Methods
Inherited methods
Rush$detect_lost_workers()Rush$empty_queue()Rush$fetch_failed_tasks()Rush$fetch_finished_tasks()Rush$fetch_new_tasks()Rush$fetch_queued_tasks()Rush$fetch_running_tasks()Rush$fetch_tasks()Rush$fetch_tasks_with_state()Rush$format()Rush$is_failed_task()Rush$is_running_task()Rush$print()Rush$print_log()Rush$push_failed_tasks()Rush$push_finished_tasks()Rush$push_tasks()Rush$read_hash()Rush$read_hashes()Rush$read_log()Rush$reconnect()Rush$reset()Rush$reset_cache()Rush$start_local_workers()Rush$start_remote_workers()Rush$start_workers()Rush$stop_workers()Rush$tasks_with_state()Rush$wait_for_tasks()Rush$wait_for_workers()Rush$worker_script()Rush$write_hashes()
RushWorker$new()
Creates a new instance of this R6 class.
Usage
RushWorker$new(
network_id,
config = NULL,
worker_id = NULL,
heartbeat_period = NULL,
heartbeat_expire = NULL
)Arguments
network_id(
character(1))
Identifier of the rush network. Manager and workers must have the same id. Keys in Redis are prefixed with the instance id.config(redux::redis_config)
Redis configuration options. IfNULL, configuration set byrush_plan()is used. Ifrush_plan()has not been called, theREDIS_URLenvironment variable is parsed. IfREDIS_URLis not set, a default configuration is used. See redux::redis_config for details.worker_id(
character(1))
Identifier of the worker. Keys in redis specific to the worker are prefixed with the worker id.heartbeat_period(
integer(1))
Period of the heartbeat in seconds. The heartbeat is updated everyheartbeat_periodseconds. Must be at least 1 second.heartbeat_expire(
integer(1))
Time to live of the heartbeat in seconds. The heartbeat key is set to expire afterheartbeat_expireseconds. Must be at leastheartbeat_period, otherwise a live worker is reaped as lost between two heartbeats. Set it larger than the longest pause a worker may experience, for example from garbage collection or swapping, because a live worker wrongly declared lost can leave a task in an inconsistent state.
RushWorker$pop_task()
Pop a task from the queue and mark it as running.
Returns NULL if no task is available.
Arguments
timeout(
numeric(1))
Time to wait for task in seconds.fields(
character())
Fields to be returned.
RushWorker$push_running_tasks()
Create running tasks.
Arguments
xss(list of named
list())
Lists of arguments for the function e.g.list(list(x1 = 1, x2 = 2), list(x1 = 3, x2 = 4)). Ifxssis empty, no tasks are created and the method returns an emptycharacter().xss_extra(list of named
list())
List of additional information stored along with the task e.g.list(list(timestamp_xs = Sys.time()), list(timestamp_xs = Sys.time())).extra(
list)
Deprecated argument for additional information stored along with the task. Usexss_extrainstead.
Returns
(character())
Keys of the tasks.
RushWorker$finish_tasks()
Save the output of tasks and mark them as finished.
Arguments
keys(
character(1))
Keys of the associated tasks.yss(list of named
list())
Lists of results for the function e.g.list(list(y1 = 1, y2 = 2), list(y1 = 3, y2 = 4)).yss_extra(list of named
list())
List of additional information stored along with the results e.g.list(list(timestamp_ys = Sys.time()), list(timestamp_ys = Sys.time())).extra(named
list())
Deprecated argument for additional information stored along with the results. Useyss_extrainstead.
RushWorker$fail_tasks()
Move running tasks to failed and optionally save the condition objects.
Arguments
keys(
character())
Keys of the running tasks to be moved.conditions(
list())
List conditions e.g.list(simpleError("Error"), simpleError("Error")). Defaults tolist(message = "Task failed").
RushWorker$set_terminated()
Mark the worker as terminated. Last step in the worker loop before the worker terminates.