-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcelery_app.py
More file actions
73 lines (57 loc) · 1.94 KB
/
celery_app.py
File metadata and controls
73 lines (57 loc) · 1.94 KB
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
"""
Helios OS — Celery Application Factory
═══════════════════════════════════════
Background job processing for settlements, minting, and IPFS pinning.
"""
import os
from celery import Celery
from celery.schedules import crontab
# Redis URL from environment
REDIS_URL = os.getenv("HELIOS_REDIS_URL", "redis://localhost:6379/0")
def make_celery(app=None):
"""Create a Celery instance, optionally bound to a Flask app."""
celery = Celery(
"helios",
broker=REDIS_URL,
backend=REDIS_URL,
include=["tasks"],
)
celery.conf.update(
# Serialization
task_serializer="json",
result_serializer="json",
accept_content=["json"],
# Timezone
timezone="UTC",
enable_utc=True,
# Reliability
task_acks_late=True,
worker_prefetch_multiplier=1,
task_reject_on_worker_lost=True,
# Result expiry (24 hours)
result_expires=86400,
# Beat schedule — automatic settlements
beat_schedule={
"run-settlement-propagation": {
"task": "tasks.run_scheduled_settlement",
"schedule": crontab(minute="*/30"), # Every 30 minutes
"args": (),
},
"health-check-integrations": {
"task": "tasks.check_integration_health",
"schedule": crontab(minute=0, hour="*/6"), # Every 6 hours
"args": (),
},
},
)
if app:
celery.conf.update(app.config)
class ContextTask(celery.Task):
abstract = True
def __call__(self, *args, **kwargs):
with app.app_context():
return self.run(*args, **kwargs)
celery.Task = ContextTask
return celery
# Module-level celery instance for `celery -A celery_app worker`
celery = make_celery()