Sandeep Prasad Kushwaha
Sandeep Prasad Kushwaha

Reputation: 1298

Run celery task for specific time period

I'm developing web app using django, and I'm using celery to run task in background. Everything is working fine, But i have one issue, I want to run celery task for the specific time period like from 2pm to 3pm.

Upvotes: 2

Views: 1757

Answers (1)

Tomáš Linhart
Tomáš Linhart

Reputation: 10210

I suppose you're using Celery beat to run periodic tasks. Your requirement should be possible using Crontab schedule. Specifically following this example that's given there:

crontab(minute=0, hour='*/3,8-17')

Execute every hour divisible by 3, and every hour during office hours (8am-5pm).

EDIT: If you want to run the task only once but want to specify the time when it's going to be started, specify ETA when calling the task. Example from the documentation:

>>> from datetime import datetime, timedelta
>>> tomorrow = datetime.utcnow() + timedelta(days=1)
>>> add.apply_async((2, 2), eta=tomorrow)

Upvotes: 2

Related Questions