Rworker: Rworker object

Description Usage Arguments Usage Details Examples

Description

The Rworker object consumes messages sent to the message broker and sends tasks to be executed in background by the process pool.

Usage

1
2
rworker(name = "celery", workers = 2, queue = "redis://localhost:6379",
  backend = "redis://localhost:6379")

Arguments

name

The name of the message queue.

workers

The number of background worker processes.

queue

A url string of type "provider://host:port".

backend

A url string of type "provider://host:port".

Usage

1
rwork <- rworker()

Details

$new() creates new Rworker instance. Process pool is started and Queue connection is established during instantiation.

$start_pool() starts all processes in the background process pool

$kill_pool() kills all processes in the background process pool

$pool processes list

$task() registers function as task to be remotelly executed

$tasks list of registered tasks

$consume() listens for message broker messages and send them to be executed by the worker process pool

$execute() method used to send tasks and arguments for background execution

$update_state() method used to gather tasks execution status from worker pool

register_backend() registers results backend

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
## Not run: 
rwork <- rworker()

# Register task
myfun <- function() { 
    Sys.sleep(5)
}
rwork$task(myfun, name='long_running_task')

# Send task for background execution
rwork$execute('long_running_task')

# Listen to messages from message queue
rwork$consume()


## End(Not run)

lecardozo/rworker documentation built on May 22, 2019, 2:47 p.m.