Skip to contents

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 owned by the worker.

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


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. If NULL, configuration set by rush_plan() is used. If rush_plan() has not been called, the REDIS_URL environment variable is parsed. If REDIS_URL is 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 every heartbeat_period seconds. 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 after heartbeat_expire seconds. Must be at least 1 second.


RushWorker$pop_task()

Pop a task from the queue and mark it as running.

Usage

RushWorker$pop_task(timeout = 1, fields = "xs")

Arguments

timeout

(numeric(1))
Time to wait for task in seconds.

fields

(character())
Fields to be returned.


RushWorker$push_running_tasks()

Create running tasks.

Usage

RushWorker$push_running_tasks(xss, extra = NULL)

Arguments

xss

(list of named list())
Lists of arguments for the function e.g. list(list(x1, x2), list(x1, x2))).

extra

(list)
List of additional information stored along with the task e.g. list(list(timestamp), list(timestamp))).

Returns

(character())
Keys of the tasks.


RushWorker$set_terminated()

Mark the worker as terminated. Last step in the worker loop before the worker terminates.

Usage

RushWorker$set_terminated()

Returns

(RushWorker)
Invisible self.


RushWorker$clone()

The objects of this class are cloneable with this method.

Usage

RushWorker$clone(deep = FALSE)

Arguments

deep

Whether to make a deep clone.