-
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathapp_celery.py
More file actions
30 lines (25 loc) · 891 Bytes
/
app_celery.py
File metadata and controls
30 lines (25 loc) · 891 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
from celery import Celery
from config import SENTRY_DSN
def make_celery(app):
celery = Celery(
app.import_name,
broker_pool_limit=1,
broker_heartbeat=None,
broker=app.config["CELERY_BROKER_URL"],
broker_connection_timeout=60,
result_backend=None,
event_queue_expires=60,
worker_prefetch_multiplier=1,
worker_log_format="%(levelname)s %(name)s/%(module)s:%(lineno)d - %(message)s",
worker_task_log_format="%(levelname)s %(name)s/%(module)s:%(lineno)d - %(message)s",
worker_concurrency=3,
)
celery.conf.update(app.config)
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
return celery