migrate background tasks to celery
This commit is contained in:
parent
efe3248c07
commit
93129333e6
7 changed files with 106 additions and 101 deletions
31
crawler/celery_app.py
Normal file
31
crawler/celery_app.py
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
import sys
|
||||
from celery import Celery
|
||||
from dotenv import load_dotenv
|
||||
import os
|
||||
|
||||
load_dotenv()
|
||||
|
||||
app = Celery(
|
||||
"celery_app",
|
||||
broker=os.getenv("CELERY_BROKER_URL", "redis://localhost:6379/0"),
|
||||
backend=os.getenv("CELERY_RESULT_BACKEND", "redis://localhost:6379/1"),
|
||||
include=["tasks.listing_tasks"],
|
||||
)
|
||||
|
||||
app.conf.update(
|
||||
task_serializer="json",
|
||||
result_serializer="json",
|
||||
accept_content=["json"],
|
||||
timezone="UTC",
|
||||
enable_utc=True,
|
||||
)
|
||||
|
||||
if __name__ == "__main__":
|
||||
try:
|
||||
with app.connection() as conn:
|
||||
conn.ensure_connection(max_retries=0)
|
||||
print("Broker connection OK")
|
||||
sys.exit(0)
|
||||
except Exception as e:
|
||||
print(f"Broker connection failed: {e}")
|
||||
sys.exit(1)
|
||||
Loading…
Add table
Add a link
Reference in a new issue