Skip to contents

Runs a command in a child process while the worker keeps the task lease alive, so work longer than one lease is not reclaimed by another worker. Use it for external tools, or for blocking R computation run through Rscript: a timer inside the blocked process cannot renew anything.

Usage

ca_process(
  task,
  command,
  args = character(),
  directory,
  timeout = Inf,
  heartbeat_seconds = task@lease_seconds/3
)

Arguments

task

A claim returned by ca_claim() or passed to an R handler.

command

Executable to run.

args

Character vector of arguments.

directory

Directory that holds this step's attempt directories. Use one directory per task and step.

timeout

Positive seconds before the command is killed, or Inf.

heartbeat_seconds

Positive renewal interval, shorter than the task's lease_seconds.

Value

The attempt directory path, after the command exits with status 0.

Details

The lease is renewed before the command starts, so nothing begins on a lost claim, and then every heartbeat_seconds. The command runs in attempt-<n> under directory and writes stdout.log and stderr.log there, so relative output paths stay inside that attempt and no later attempt overwrites an earlier one's files. An existing attempt directory is an error. Publish results by returning paths from a ca_step() callback: only the current lease holder can save that checkpoint.

Lease loss, including from ca_cancel(), a timeout, or an error or interrupt in the supervising code kills the command's process tree. Lease loss raises canard_lease_lost; a nonzero exit or timeout raises canard_process_error, which a handler records as an ordinary failure.

Overlap remains possible: a paused or partitioned worker can outlive its lease before the next heartbeat. Work submitted to Slurm or a similar backend needs that backend's own job identity, since supervising the submitting command does not supervise the job.