Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(beat): add beat shutdown signals #8551

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions celery/beat.py
Original file line number Diff line number Diff line change
Expand Up @@ -658,8 +658,10 @@ def sync(self):

def stop(self, wait=False):
info('beat: Shutting down...')
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)

def get_scheduler(self, lazy=False,
extension_namespace='celery.beat_schedulers'):
Expand Down
2 changes: 2 additions & 0 deletions celery/signals.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,8 @@
# - Beat
beat_init = Signal(name='beat_init')
beat_embedded_init = Signal(name='beat_embedded_init')
beat_shutting_down = Signal(name='beat_shutting_down')
beat_shutdown = Signal(name='beat_shutdown')

# - Eventlet
eventlet_pool_started = Signal(name='eventlet_pool_started')
Expand Down
19 changes: 19 additions & 0 deletions docs/userguide/signals.rst
Original file line number Diff line number Diff line change
Expand Up @@ -656,6 +656,25 @@ beat` is started as an embedded process.

Sender is the :class:`celery.beat.Service` instance.

.. signal:: beat_shutting_down

``beat_shutting_down``
Copy link
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

~~~~~~~~~~~~~~~~~~~~~~~~

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.


Eventlet Signals
----------------

Expand Down
13 changes: 13 additions & 0 deletions t/unit/app/test_beat.py
Original file line number Diff line number Diff line change
Expand Up @@ -817,6 +817,19 @@ def test_start_manages_one_tick_before_shutdown(self):
s.start()
assert s._is_shutdown.is_set()

@patch("celery.signals.beat_shutdown")
@patch("celery.signals.beat_shutting_down")
@patch("celery.signals.beat_init")
def test_lifecycle_signals(self, beat_init: Mock, beat_shutting_down: Mock, beat_shutdown: Mock):
s, _ = self.get_service()
s.scheduler.shutdown_service = s
s.start()
beat_init.send.assert_called_with(sender=s)
s.stop(wait=False)
beat_shutting_down.send.assert_called_with(sender=s)
s.stop(wait=True)
beat_shutdown.send.assert_called_with(sender=s)


class test_EmbeddedService:

Expand Down