2

I have to execute a task at a specific time, which is specified by the user. This will not be fix time... It will be according to user...

On that time I have to execute my task...

To achieve this I tried to use django-cron also tried to use django-crontab...

But in both case either we have to specify cron details in settings.py or we've to execute runcron commands.

I also checked django-celery (I don't have any idea about celery much. I may be wrong).

In celery we have to specify time while defining task...

Can any one help me how can I do this...

I am using django as a backend...

Shreejay Pendse
  • 194
  • 2
  • 13
  • 1
    You'll have to use celery. It's the best thing to run scheduled tasks. Please refer to this documentation and tutorial provided on their website : http://docs.celeryproject.org/en/latest/getting-started/first-steps-with-celery.html – pissall Dec 04 '17 at 12:45
  • https://stackoverflow.com/questions/47489274/how-to-execute-tasks-in-celery-using-datetime-from-mysql/47491358#47491358 find the delta time and use it as `eta` – HQM Dec 05 '17 at 16:32

1 Answers1

1

To execute a task at specified date and time you can use eta attribute of apply_async while calling task as mentioned in docs(http://docs.celeryproject.org/en/latest/userguide/calling.html#eta-and-countdown)

your_task.apply_async(kwargs={}, eta="your_send_time")

## Note: your_send_time should be of type `datetime`.
Parul Dixit
  • 364
  • 1
  • 10