Celery Note === ## Intro - A - B ``` celery_app = Celery('my_app' , broker='amqp://localhost//' , backend='db+postgresql://user:password@localhost/db_name', , include=['my_app.my_task']) ``` --- ## Calling -1 `delay` & `apply_async` ([calling](http://docs.jinkan.org/docs/celery/userguide/calling.html)) --- ## Calling -2 `delay` vs `apply_async` `delay` is clearly convenient, but if you want to set additional execution options you have to use `apply_async` ([Celery调用任务的方法delay()和apply_async()的区别](https://hushuikun.com/celeryzhi-ding-shi-jian-zhi-xing-dan-ci-ren-wu/)) --- ### apply_sync -1 - `countdown` - expire - timeout - Possible reasons for broken deadlines may include many items waiting in the queue, or heavy network latency. - monitoring congestion: [Munin](http://docs.jinkan.org/docs/celery/userguide/monitoring.html#monitoring-munin) - When a worker receives an expired task it will mark the task as `REVOKED` (`TaskRevokedError`). --- ### apply_sync -2 - linking - callbacks - `link` - one task follow another - return result - errbacks - `link_error` - exception - return task_id - can be expressed in [] (execute in order) --- ### apply_sync -3 - retry --- ### apply_sync -4 ## Result ? ``` result = add.apply_sync(args=[1,1]) ``` `result.task_id` = `result.id` `result.status` ([ref](https://docs.celeryproject.org/en/latest/userguide/tasks.html#started)) * PENDING * STARTED * SUCCESS * FAILURE * RETRY * REVOKE `result.get()` ## *important [Celery Execution Pools: What is it all about?](https://www.distributedpython.com/2018/10/26/celery-execution-pool/) - prefork - gevent - eventlet - solo --- ### rtabbitmq [add_user & set_permissions](https://medium.com/@krishnadey30/setting-up-a-task-queue-using-celery-and-rabbitmq-e73f8fd15de0) ref:
{"metaMigratedAt":"2023-06-15T02:02:41.832Z","metaMigratedFrom":"Content","title":"Celery Note","breaks":true,"contributors":"[{\"id\":\"afee4829-e30b-4a44-a9f0-7e94afca9731\",\"add\":2141,\"del\":229}]"}
    224 views