I'm using Celery, and it works for async, but I need to set up an operation to a specific datetime.
For example "on the 30th of August, 2019, at 11:35, do this."
My celery.py is very simple now, but it works:
import time
from datetime import datetime, timedelta
from datetime import date
from celery import shared_task,current_task, task
from celery import Celery
app = Celery()
@app.task
def test():
print ('1')
todaynow = datetime.now()
print todaynow
I call it from view and run print on rabbit
Any idea for how to program a task?
ty
EDIT:
I try in view to call "test"
test.apply_async(eta=datetime(2019, 7, 31, 6, 28))
in flower it receive the task but not execute it, why?
Run the scheduler When using Django, you will usually have one process that is responsible for serving web requests and a separate one that takes care of processing tasks. During local development, these two processes are: web requests: ./manage.py runserver. async tasks: ./manage.py qcluster.
As you build and scale a Django app you'll inevitably need to run certain tasks periodically and automatically in the background. Some examples: Generating periodic reports. Clearing cache. Sending batch e-mail notifications.
celery beat is a scheduler. It kicks off tasks at regular intervals, which are then executed by the worker nodes available in the cluster. By default the entries are taken from the CELERYBEAT_SCHEDULE setting, but custom stores can also be used, like storing the entries in an SQL database.
An async view function in Django is detected by the annotation async def , which then runs the async view in a thread within its own event loop. This gives the benefit of being able to do and run tasks concurrently inside the async views.
To run a task at a specific time you can pass the eta
parameter to apply_async
test.apply_async(eta=datetime.datetime(2019, 8, 30, 11, 35))
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