from celery import Celery

from utils.model import WalmartInfo, WalmartReview, WalmartReviewStats

app = Celery('tasks', broker='amqp://guest@localhost//')


@app.task
def insert_product_info_task(data, sku):
    item = WalmartInfo()
    item.single_insert(data, sku)


@app.task(autoretry_for=(Exception,), retry_kwargs={'max_retries': 5, 'countdown': 5})
def insert_product_reviews_task(data: list, sku):
    item = WalmartReview()
    item.bulk_upsert(data, sku)


@app.task
def insert_product_stat_task(stats, sku):
    stat = WalmartReviewStats()
    stat.single_insert(stats, sku)
