Skip to content

feat(beat): add beat shutdown signals - #8551

Open
noirbizarre wants to merge 6 commits into
celery:mainfrom
noirbizarre:beat/shutdown-signals
Open

noirbizarre wants to merge 6 commits into
celery:mainfrom
noirbizarre:beat/shutdown-signals

Conversation

@noirbizarre

Copy link
Copy Markdown
Contributor

Description

This PR is a very quick addition: it provides shutdown signals to beat using the same convention as the worker:

  • signals.beat_shutting_down dispatched when the beat process is starting its shutdown
  • signals.beat_shutdown dispatched when the beat process has completed its shutdown

Note: there was no existing test on dispatched signals so I added one testing those lifecycle signals

@codecov

codecov Bot commented Oct 3, 2023 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 89.16%. Comparing base (0ec71f9) to head (8f320ed).
⚠️ Report is 215 commits behind head on main.

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           
Flag Coverage Δ
unittests 89.14% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

@auvipy
auvipy self-requested a review October 3, 2023 10:49
@noirbizarre
noirbizarre force-pushed the beat/shutdown-signals branch from 1da201c to 1133ae6 Compare October 3, 2023 10:52

.. signal:: beat_shutting_down

``beat_shutting_down``

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we think about better naming? also it would be nice to have some more context about when and why this should be used

@auvipy auvipy added this to the 5.4 milestone Nov 8, 2023
@Nusnus Nusnus modified the milestones: 5.4, 5.5 Jun 25, 2024
@auvipy auvipy removed this from v5.4 Jun 10, 2025
@auvipy auvipy modified the milestones: 5.5.0, 5.7.0 Jun 10, 2025
@auvipy auvipy self-assigned this Jun 10, 2025
@Nusnus
Nusnus force-pushed the beat/shutdown-signals branch from d74f712 to 225abe7 Compare November 1, 2025 22:03
@auvipy
auvipy requested a review from Copilot November 6, 2025 13:58

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 in celery/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

Comment thread docs/userguide/signals.rst Resolved
Comment on lines +659 to +676
.. 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.

Copilot AI Nov 6, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot generated this review using guidance from repository custom instructions.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@noirbizarre can you please address this?

Comment thread celery/beat.py
Comment on lines +663 to +666
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)

Copilot AI Nov 6, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_shutdown is sent immediately without waiting for the beat loop to fully stop (_is_stopped event).
  • When wait=True, beat_shutdown is 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?

Copilot generated this review using guidance from repository custom instructions.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and cross check this? @noirbizarre

@Nusnus
Nusnus force-pushed the beat/shutdown-signals branch from 63e13c0 to 982e490 Compare November 9, 2025 13:18
@auvipy auvipy modified the milestones: 5.7.0, 5.8.0 Aug 26, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants