brightly-ai / tasks.py
beweinreich's picture
integrated celery
b9a27ee
raw
history blame
673 Bytes
# tasks.py
import logging
from celery import Celery
from db.db_utils import get_connection, store_result_to_db
app = Celery('tasks', broker='redis://localhost:6379/0', backend='redis://localhost:6379/0')
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_async(run_key, mapping):
logging.info(f"Inserting result for run_key: {run_key}, mapping: {mapping['input_word']}")
db_conn = get_connection()
db_cursor = db_conn.cursor()
store_result_to_db(db_cursor, db_conn, run_key, mapping)
db_conn.close()