Я запускаю задачу в celery
(с redis
).
create_article_from_gsheet.delay()
app / init .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 / celery_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 / article / helpers / gsheets / py
from webapp import celery as celery_app
@celery_app.task
def create_article_from_gsheet():
...
#celery -A webapp.runcelery: сельдерей рабочий
-------------- 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 -A webapp.runcelery : сельдерей бит
__ - ... __ - _
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
. Есть подключение
Не понимаю, в чем может быть проблема?