Runs as a worker process that continuously fetches and executes tasks from a project until no tasks remain or the project is stopped.
Value
Does not return normally. Stops when: no more tasks are available, the project is stopped, or runtime limit is reached (SLURM only).
Details
This function implements the worker loop:
Request a task from the database (atomically)
Update task status to "working"
Execute
fun(task_id, ...)Update task status to "finished" (or "failed" if error)
Repeat until no more tasks or stopping condition
Workers automatically:
Add random delays to reduce database contention
Track runtime to respect SLURM walltime limits
Reconnect to database on connection failures
Log progress and errors to console
Your worker function should:
Check if output already exists (idempotent)
Save results to disk (not return them)
Handle errors gracefully or let them propagate
For SLURM resources, set the TASKQUEUE_RESOURCE environment variable
to enable automatic walltime management.
Examples
if (FALSE) { # \dontrun{
# Not run:
# Define worker function
my_task <- function(task_id, param1, param2) {
out_file <- sprintf("results/task_%04d.Rds", task_id)
if (file.exists(out_file)) return() # Skip if done
result <- expensive_computation(task_id, param1, param2)
saveRDS(result, out_file)
}
# Run worker locally (for testing)
worker("test_project", my_task, param1 = 10, param2 = "value")
} # }