diff --git a/bd_api/apps/account/tasks.py b/bd_api/apps/account/tasks.py index ed9017ff..00f1df25 100644 --- a/bd_api/apps/account/tasks.py +++ b/bd_api/apps/account/tasks.py @@ -3,11 +3,13 @@ from django.db.models.query import QuerySet from django.http import HttpRequest from djstripe.models import Subscription as DJStripeSubscription +from huey.contrib.djhuey import task from loguru import logger from bd_api.apps.account.models import Account, Subscription +@task def sync_subscription_task( modeladmin: ModelAdmin = None, request: HttpRequest = None, diff --git a/bd_api/apps/api/v1/tasks.py b/bd_api/apps/api/v1/tasks.py index a7d17e37..7da17973 100644 --- a/bd_api/apps/api/v1/tasks.py +++ b/bd_api/apps/api/v1/tasks.py @@ -13,11 +13,11 @@ from bd_api.apps.api.v1.models import Table from bd_api.custom.client import get_credentials -from bd_api.utils import prod_task +from bd_api.utils import production_only -@prod_task @periodic_task(crontab(day_of_week="0", hour="3", minute="0")) +@production_only def update_table_metadata_task( modeladmin: ModelAdmin = None, request: HttpRequest = None, @@ -93,13 +93,13 @@ def get_uncompressed_file_size(table, bq_table): logger.error(e) -@prod_task @periodic_task(crontab(day_of_week="1-6", hour="5", minute="0")) +@production_only def update_search_index_task(): - call_command("update_index", batchsize=100, workers=4) + call_command("update_index", batchsize=100) -@prod_task @periodic_task(crontab(day_of_week="0", hour="5", minute="0")) +@production_only def rebuild_search_index_task(): - call_command("rebuild_index", interactive=False, batchsize=100, workers=4) + call_command("rebuild_index", interactive=False, batchsize=100) diff --git a/bd_api/utils.py b/bd_api/utils.py index c01a5538..e30a8e45 100644 --- a/bd_api/utils.py +++ b/bd_api/utils.py @@ -1,4 +1,5 @@ # -*- coding: utf-8 -*- +from functools import wraps from os import getenv API_URL = getenv("BASE_URL_API", "https://localhost:8080") @@ -33,9 +34,10 @@ def is_prod(): return False -def prod_task(func): +def production_only(func): """Decorator that avoids function call if it isn't production""" + @wraps(func) def wrapper(*args, **kwargs): if is_prod(): return func(*args, **kwargs)