brightly-ai / tasks.py
beweinreich's picture
added in dockerfile
773fa99
raw
history blame
No virus
665 Bytes
# tasks.py
import os
import logging
from dotenv import load_dotenv
from celery import Celery
from db.db_utils import get_connection, store_result_to_db
load_dotenv()
REDIS_URL = os.environ['REDIS_URL']
app = Celery('tasks', broker=REDIS_URL, backend=REDIS_URL)
app.conf.update(
result_expires=3600,
task_serializer='json',
result_serializer='json',
accept_content=['json'],
timezone='UTC',
enable_utc=True,
)
@app.task
def insert_result(run_key, mappings):
db_conn = get_connection()
db_cursor = db_conn.cursor()
for mapping in mappings:
store_result_to_db(db_cursor, db_conn, run_key, mapping)
db_conn.close()