Python芹菜收到类型为的未注册任务-导入应用程序错误
我无法导入芹菜应用程序以从主Python应用程序运行任务。我希望能够从myprogram.py文件运行芹菜任务 我的芹菜app.py文件如下:Python芹菜收到类型为的未注册任务-导入应用程序错误,python,import,celery,Python,Import,Celery,我无法导入芹菜应用程序以从主Python应用程序运行任务。我希望能够从myprogram.py文件运行芹菜任务 我的芹菜app.py文件如下: import celery app = celery.Celery('MyApp', broker='redis://localhost:6379/0') app.conf.broker_url = 'redis://localhost:6379/0' app.conf.result_backend = 'redis://localhost:6379
import celery
app = celery.Celery('MyApp', broker='redis://localhost:6379/0')
app.conf.broker_url = 'redis://localhost:6379/0'
app.conf.result_backend = 'redis://localhost:6379/0'
app.autodiscover_tasks()
@app.task(ignore_result=True)
def task_to_run():
print("Task Running")
# The following call runs a worker in celery
task_to_run.delay()
if __name__ == '__main__':
app.start()
应用程序结构
- projectfolder/core/celery_app.py#celery app
- projectfolder/core/myprogram.py#我的Python应用程序
- projectfolder/core/其他python文件
from .celery_app import task_to_run
task_to_run.delay()
错误:
Received unregistered task of type 'projectfolder.core.celery_app.task_to_run'.
The message has been ignored and discarded.
Did you remember to import the module containing this task?
Or maybe you're using relative imports?
strategy = strategies[type_]
KeyError: 'projectfolder.core.celery_app.task_to_run'
谢谢很有意思,我不知道
自动发现任务
,我想它在4.1中是新的
正如我在中看到的,此函数获取要搜索的包列表。您可能希望使用以下名称来命名它:
app.autodiscover\u任务(['core.cellery\u app'])
或者,最好将任务提取到一个名为tasks.py
的单独文件中,然后它将是:
app.autodiscover\u任务(['core'])
或者,您可以在创建芹菜
实例时使用inculde
参数:
app=芹菜。芹菜('MyApp',broker='redis://localhost:6379/0,include=['core.cellery\u app'])
或您的任务所在的任何位置
祝你好运有趣的是,我不知道什么是
自动发现任务
,我想这是4.1中的新功能
正如我在中看到的,此函数获取要搜索的包列表。您可能希望使用以下名称来命名它:
app.autodiscover\u任务(['core.cellery\u app'])
或者,最好将任务提取到一个名为tasks.py
的单独文件中,然后它将是:
app.autodiscover\u任务(['core'])
或者,您可以在创建芹菜
实例时使用inculde
参数:
app=芹菜。芹菜('MyApp',broker='redis://localhost:6379/0,include=['core.cellery\u app'])
或您的任务所在的任何位置
祝你好运