flask celery 不运行任务

roqulrg3  于 2021-06-10  发布在  Redis
关注(0)|答案(1)|浏览(376)

我在计算机中运行任务 celery (与 redis ).

create_article_from_gsheet.delay()

应用程序/初始.py

from celery import Celery
from webapp.utils.celery_util import init_celery
​
​
celery = Celery('webapp', config_source="webapp.celeryconfig")
​
​
def create_app(object_name: str):
    ...
    app.config.from_object(object_name)
    init_celery(app, celery=celery)
    ...
    return app

webapp/celeryconfig.py

broker_url = 'redis://localhost:6379/0'
imports = ('webapp.articles.helpers.gsheets',)
result_backend = 'redis://localhost:6379'
​```
​

# webapp/runcelery.py

​```
import os
​
from webapp import celery, create_app
from webapp.utils.celery_util import init_celery
​
​
env = os.environ.get("WEBAPP_ENV", "dev")
app = create_app("config.%sConfig" % env.capitalize())
init_celery(app, celery)

webapp/utils/celeri\ u util.py

def init_celery(app, celery):
    TaskBase = celery.Task
​
    class ContextTask(TaskBase):
        abstract = True
        def __call__(self, *args,**kwargs):
            with app.app_context():
                return TaskBase.__call__(self, *args,**kwargs)
    celery.Task = ContextTask

webapp/文章/助手/gsheets/py

from webapp import celery as celery_app
​
​
@celery_app.task
def create_article_from_gsheet():
   ...

​ #celery -一个网络应用程序。runcelery:celery worker

-------------- celery@DESKTOP-V4QR5B3 v4.4.7 (cliffs)
---*****-----
--*******---- Windows-10-10.0.18362-SP0 2020-08-07 14:06:44
-***--- * ---
-**---------- [config]
-**---------- .> app:         webapp:0x2b60bdca640
-**---------- .> transport:   redis://localhost:6379/0
-**---------- .> results:     redis://localhost:6379/
-***--- * --- .> concurrency: 4 (prefork)
--*******---- .> task events: OFF (enable -E to monitor tasks in this worker)
---*****-----
 -------------- [queues]
                .> celery           exchange=celery(direct) key=celery

[tasks]
  . webapp.articles.helpers.gsheets.create_article_from_gsheet

celery -一个网络应用程序。runcelery:celery beat

__    -    ... __   -        _
LocalTime -> 2020-08-07 13:42:20
Configuration ->
    . broker -> redis://localhost:6379/0
    . loader -> celery.loaders.app.AppLoader
    . scheduler -> celery.beat.PersistentScheduler
    . db -> celerybeat-schedule
    . logfile -> [stderr]@%WARNING
    . maxinterval -> 5.00 minutes (300s)

推出 redis . 有联系
我不明白问题出在哪里?

n53p2ov0

n53p2ov01#

看起来你在windows机器上运行这个。celery 4.x不支持windows。
https://docs.celeryproject.org/en/master/faq.html#does-celery 支持窗口

相关问题