Created
March 26, 2023 16:13
-
-
Save ankurdhuriya/ba178c8d1d71ca93730ef94ecec35f99 to your computer and use it in GitHub Desktop.
Celery Heartbeats Example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
In this example, we're configuring Celery to use heartbeats. | |
We've set the worker_heartbeat option to 120 seconds, which means | |
that each worker will send a heartbeat message to the broker every 2 minutes. | |
This can help to ensure that tasks are not lost if a worker goes offline or crashes. | |
""" | |
from celery import Celery | |
app = Celery('tasks', broker='pyamqp://guest@localhost//') | |
# Configure Celery to use heartbeats | |
app.conf.update( | |
worker_heartbeat=120, # Send a heartbeat every 120 seconds | |
) | |
@app.task | |
def add(x, y): | |
return x + y |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment