Celery⽆法获取tasks任务⾏为的解决办法前⾔:
之前⼀直使⽤celery本来好好的,但是昨天更新代码的时候celery出了⼩问题,celery⽆法获取新写的tasks任务
后⾯通过查看官⽅⽂档有⾃动获取的⽅法。主要是 使⽤ autodiscover_tasks()
autodiscover_tasks(lf, packages=None,
公司培训总结related_name='tasks', force=Fal):
"""Auto-discover task modules.
Searches a list of packages for a "tasks.py" module (or u
related_name argument).
If the name is empty, this will be delegated to fix-ups (e.g., Django).
For example if you have a directory layout like this:
.. code-block:: text
保持冷静
foo/__init__.py
tasks.py
有趣的演讲主题
models.py
夜间外阴瘙痒bar/__init__.py
tasks.py
models.py
baz/__init__.py红包灯笼怎么做
models.py
Then calling ``app.autodiscover_tasks(['foo', bar', 'baz'])`` will
result in the modules ``foo.tasks`` and ``bar.tasks`` being imported.
Arguments:
过桥米线的做法
packages (List[str]): List of packages to arch.
素食主义
This argument may also be a callable, in which ca the
value returned is ud (for lazy evaluation).
related_name (str): The name of the module to find. Defaults
to "tasks": meaning "look for 'module.tasks' for every
第四色激情module in ``packages``."
force (bool): By default this call is lazy so that the actual
auto-discovery won't happen until an application imports
the default modules. Forcing will cau the auto-discovery
to happen immediately.
看解释以后只要传⼊对应的tasks.py⽬录的路径就可以,因此我的代码就是celery.autodiscover_tasks(['app.script','app.script.main'])
然后重启celery以后,新写的tasks任务就⾃动发现了