Repository navigation
feat(beat): add beat shutdown signals - #8551
noirbizarre wants to merge 6 commits into
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #8551 +/- ##
=======================================
Coverage 89.16% 89.16%
=======================================
Files 153 153
Lines 20314 20318 +4
Branches 2412 2412
=======================================
+ Hits 18113 18117 +4
Misses 1896 1896
Partials 305 305
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. |
1da201c to
1133ae6
Compare
|
|
||
| .. signal:: beat_shutting_down | ||
|
|
||
| ``beat_shutting_down`` |
There was a problem hiding this comment.
can we think about better naming? also it would be nice to have some more context about when and why this should be used
d74f712 to
225abe7
Compare
There was a problem hiding this comment.
Pull Request Overview
This PR adds two new signals for the beat service shutdown lifecycle: beat_shutting_down and beat_shutdown. These signals follow the existing pattern established by worker lifecycle signals (worker_shutting_down and worker_shutdown), allowing applications to hook into the beat shutdown process for cleanup or notification purposes.
Key changes:
- New signal definitions in
celery/signals.py - Signal dispatch implementation in the
Service.stop()method incelery/beat.py - Documentation for both signals in the signals user guide
- Comprehensive test coverage validating signal dispatch during the beat lifecycle
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
celery/signals.py |
Adds beat_shutting_down and beat_shutdown signal definitions in the Beat signals section |
celery/beat.py |
Implements signal dispatch in Service.stop() method: beat_shutting_down at start of shutdown, beat_shutdown after optional wait |
docs/userguide/signals.rst |
Documents both new signals with descriptions of when they are dispatched and their sender |
t/unit/app/test_beat.py |
Adds test_lifecycle_signals to verify correct signal dispatch during beat service lifecycle |
| .. signal:: beat_shutting_down | ||
|
|
||
| ``beat_shutting_down`` | ||
| ~~~~~~~~~~~~~~~~~~~~~~~~ | ||
|
|
||
| Dispatched when the :program:`celery beat` begins the shutdown process. | ||
|
|
||
| Sender is the :class:`celery.beat.Service` instance. | ||
|
|
||
| .. signal:: beat_shutdown | ||
|
|
||
| ``beat_shutdown`` | ||
| ~~~~~~~~~~~~~~~~~~~ | ||
|
|
||
| Dispatched when the :program:`celery beat` finished its shutdown process. | ||
|
|
||
| Sender is the :class:`celery.beat.Service` instance. | ||
|
|
There was a problem hiding this comment.
These new signals should include a versionadded:: directive to document when they were introduced. Should we add version information for these new signals? For example:
.. signal:: beat_shutting_down
``beat_shutting_down``
~~~~~~~~~~~~~~~~~~~~~~~~
.. versionadded:: <version>
Dispatched when the :program:`celery beat` begins the shutdown process.| signals.beat_shutting_down.send(sender=self) | ||
| self._is_shutdown.set() | ||
| wait and self._is_stopped.wait() # block until shutdown done. | ||
| signals.beat_shutdown.send(sender=self) |
There was a problem hiding this comment.
The beat_shutdown signal is sent at the end of the stop() method regardless of the wait parameter value. This means:
- When
wait=False,beat_shutdownis sent immediately without waiting for the beat loop to fully stop (_is_stoppedevent). - When
wait=True,beat_shutdownis sent after the beat loop has fully stopped.
Is this intended? The signal documentation states it's "dispatched when the :program:celery beat finished its shutdown process," which suggests it should only be sent after the shutdown is complete. Should we consider moving beat_shutdown to be sent only after _is_stopped is set, or updating the documentation to clarify the current behavior?
Co-authored-by: Copilot <[email protected]>
63e13c0 to
982e490
Compare
Description
This PR is a very quick addition: it provides shutdown signals to
beatusing the same convention as the worker:signals.beat_shutting_downdispatched when the beat process is starting its shutdownsignals.beat_shutdowndispatched when the beat process has completed its shutdownNote: there was no existing test on dispatched signals so I added one testing those lifecycle signals