Skip to content

Commit

Permalink
fix: adapt production only decorator (#529)
Browse files Browse the repository at this point in the history
  • Loading branch information
vncsna authored Dec 7, 2023
1 parent 4e30e84 commit 081ab8c
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
2 changes: 2 additions & 0 deletions bd_api/apps/account/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
12 changes: 6 additions & 6 deletions bd_api/apps/api/v1/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)
4 changes: 3 additions & 1 deletion bd_api/utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# -*- coding: utf-8 -*-
from functools import wraps
from os import getenv

API_URL = getenv("BASE_URL_API", "https://localhost:8080")
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 081ab8c

Please sign in to comment.