Is it possible to run the django celery crontab very 30 seconds DURING SPECIFIC HOURS?
There are only settings for minutes, hours and days.
I have the crontab working, but I'd like to run it every 30 seconds, as opposed to every minute.
Alternatively...
Is it possible to turn the interval on for 30 seconds, and turn on the interval schedule only for a certain period of the day?
You could just use
from datetime import timedelta
@periodic_task(run_every=timedelta(seconds=30))
def thirty_second_task():
now = datetime.now()
if now.hour == 12 or now.hour == 9:
your code goes here`
That will run the function every thirty seconds, but it will only run your code if the hour value of the current time is 12 or 9.
Very first example they have in the documentation is...
Example: Run the tasks.add task every 30 seconds.
from datetime import timedelta CELERYBEAT_SCHEDULE = { "runs-every-30-seconds": { "task": "tasks.add", "schedule": timedelta(seconds=30), "args": (16, 16) }, }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With