I'm using celery and django-celery. I have defined a periodic task that I'd like to test. Is it possible to run the periodic task from the shell manually so that I view the console output?
相关问题
- how to define constructor for Python's new Nam
- streaming md5sum of contents of a large remote tar
- How to get the background from multiple images by
- Django __str__ returned non-string (type NoneType)
- Evil ctypes hack in python
If you means just trigger a task when the condition is not satisfied, for example, the periodic time not meet. You can do it in two steps.
1.Get your task id.
You can do it by typing.
You will see something like
app.tasks.update_something
. If nothing, it is probably thatcelery
was not started. Just run it.2.Run the task with
celery call
For more details, just type
Have you tried just running the task from the Django shell? You can use the
.apply
method of a task to ensure that it is run eagerly and locally.Assuming the task is called
my_task
in Django appmyapp
in atasks
submodule:The result instance has the same API as the usual
AsyncResult
type, except that the result is always evaluated eagerly and locally and the.apply()
method will block until the task is run to completion.I think you'll need to open two shells: one for executing tasks from the Python/Django shell, and one for running
celery worker
(python manage.py celery worker
). And as the previous answer said, you can run tasks usingapply()
orapply_async()
I've edited the answer so you're not using a deprecated command.