How to structure celery tasks

后端 未结 2 1316
庸人自扰
庸人自扰 2021-02-05 02:57

I have 2 types of task: async tasks and schedule tasks. So, here is my dir structure:

proj
  |
  -- tasks
      |
      -- __init__.py
      |
      -- celeryapp         


        
2条回答
  •  盖世英雄少女心
    2021-02-05 03:39

    Based on celery documentation you can import a structure of celery tasks like this:

    For example if you have an (imagined) directory tree like this:

    |
    |-- foo
    |    |-- __init__.py
    |    |-- tasks.py
    |
    |-- bar
         |-- __init__.py
         |-- tasks.py
    

    Then calling app.autodiscover_tasks(['foo', bar']) will result in the modules foo.tasks and bar.tasks being imported.

提交回复
热议问题