Reputation: 41665
https://docs.celeryproject.org/en/latest/userguide/periodic-tasks.html#entries mentions add_periodic_task
I'm not getting what is test.s and test.s('hello')
and not just test('hello')
from celery import Celery
from celery.schedules import crontab
app = Celery()
@app.on_after_configure.connect
def setup_periodic_tasks(sender, **kwargs):
# Calls test('hello') every 10 seconds.
sender.add_periodic_task(10.0, test.s('hello'), name='add every 10')
# Calls test('world') every 30 seconds
sender.add_periodic_task(30.0, test.s('world'), expires=10)
# Executes every Monday morning at 7:30 a.m.
sender.add_periodic_task(
crontab(hour=7, minute=30, day_of_week=1),
test.s('Happy Mondays!'),
)
@app.task
def test(arg):
print(arg)
and what would be the sender
? I'd liket call add_periodic_task
outside of @app.on_after_configure.connect
Upvotes: 1
Views: 514
Reputation: 4161
.s()
is the task signature - think of it as placeholder for running a task - test('hello')
would invoke your task immediately, which is not what you would want when you just want to instruct Celery to call the task periodically in setup_periodic_tasks
.
Upvotes: 1