Skip to content

devlanes is in beta and not ready for production use.Report an issue

Run workers and replicas

A queue consumer, a scheduler or another background process runs as a service like any other, with a few settings because nothing sends it requests.

::example{slug="workflows-queue-workers"}

devlanes.yaml
services:
worker:
run: [node, worker.mjs]
cwd: worker
ready:
log: "worker ready"
stop:
signal: SIGINT
timeout: 15s
keep_awake: true

Have the worker print one line once it is connected, and the ready check waits for that line. The stop settings give it the signal it finishes its current job on, and time to do so. Keeping the lane awake stops devlanes from freezing a lane that gets no requests while the worker runs; Throttling and freezing explains freezing.

devlanes.yaml
services:
worker:
replicas: 2
env:
WORKER_ID: ${{ replica.index }}
ready:
log: worker ${{ replica.index }} ready

The copies run as worker.1 and worker.2, each with its own port, and the replica index tells each one which it is. The service’s name stands for all its copies, so this stops both:

~/dev/myapp
$ devlanes stop worker

Name one copy, such as worker.2, to act on it alone.

A command that exits when its work is done, such as a cleanup, is a task; as a service it would show as failed. Run installs, migrations and seeds covers tasks.