Skip to content

Add restart signal listener to restart workers after a deployment - #59

Merged
DavidBadura merged 2 commits into
1.7.xfrom
restart-signal-listener
Oct 5, 2026
Merged

DavidBadura merged 2 commits into
1.7.xfrom
restart-signal-listener

Conversation

@DavidBadura

Copy link
Copy Markdown
Member

Long-running workers keep the code they were started with, so after a deployment they have to be restarted somehow. This adds a StopWorkerOnRestartSignalListener, similar to messenger:stop-workers in Symfony: it remembers when the worker started and stops it once a given file has been modified after that. Running touch var/worker-restart in the deployment is enough, the file can stay in place for the next one. It can be enabled through the new restartSignalFile option in create().

The modification time is only checked after each iteration, and the stat cache is cleared before every check, otherwise PHP would keep returning the old filemtime. Since filemtime has second precision, a touch in the same second the worker started is ignored, which should be fine as that worker already runs the new code.

The custom listener example in the events docs was a "new deployment" listener, which is now built in, so I replaced it with a maintenance mode example.

@DavidBadura DavidBadura added this to the 1.7.0 milestone Oct 4, 2026
@DavidBadura DavidBadura added the enhancement New feature or request label Oct 4, 2026
StopWorkerOnRestartSignalListener stops the worker once a given file is
touched after the worker has started. Touching the file during a
deployment makes all running workers restart with the new code. It can
be enabled with the new restartSignalFile option in create().
The start time now comes from the PSR-20 clock, which makes the check
for a file touched in the same second as the start deterministic in
tests. The stat cache test changes the file from another process, since
touching it from within the test process clears the cache anyway.
@DavidBadura
DavidBadura force-pushed the restart-signal-listener branch from d480d6f to 56e81fb Compare October 5, 2026 07:22
@DavidBadura
DavidBadura merged commit 100b0b2 into 1.7.x Oct 5, 2026
16 checks passed
@DavidBadura
DavidBadura deleted the restart-signal-listener branch October 5, 2026 07:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants