celery

1 Don't pass model objects to tasks

1.1 Since tasks don't run immediately, by the time a task runs and looks at a model object that was passed to it, the corresponding record in the database might have changed. If the task then does something to the model object and saves it, those changes in the database are overwritten by older data.

It's almost always safer to save the object, pass the record's key, and look up the object again in the task

myobject.save()
mytask.delay(myobject.pk)
@task
def mytask(pk):
    myobject = MyModel.objects.get(pk=pk)
    ...

2 celery 清空队列中所有未完成的任务

celery -A proj purge

3 celery 设置worker 的数量

-c + worker_number

4 django celery 不执行 send due task