Skip to content

Worker process

The replica starts the SDK worker. You do not pass a token on the command line.

Terminal window
python -m surfra.worker

The process exits if any of these are empty:

Variable Who sets it
SURFRA_MASTER Autoscaler
SURFRA_REPLICA_TOKEN Autoscaler. One token, used by every worker on that replica
SURFRA_ENTRYPOINT Path to the handler file inside the image

SURFRA_ONCE=1 runs a single successful batch and then exits. Leave it unset in production.

  1. Import the entrypoint so @surfra.warmup and @surfra.handler register.
  2. Run warmup once.
  3. Start concurrent_workers threads. Each thread calls POST /v1/workers/register and gets its own worker id.
  4. Each thread polls POST /v1/workers/next for up to batch_size max leased stages.
  5. The handler runs. Results are completed one stage at a time. None, a short list, or an exception fails every stage in that batch.

The replica token can register at most num_workers worker ids. The first register in a process raises that cap to concurrent_workers when the handler asks for more.