2020-09-27 08:02:44 +00:00
|
|
|
from celery import shared_task
|
2020-12-10 09:12:39 +00:00
|
|
|
from django.utils.translation import gettext_lazy as _
|
2020-09-27 08:02:44 +00:00
|
|
|
|
2020-12-10 09:47:35 +00:00
|
|
|
from orgs.models import Organization
|
|
|
|
from orgs.utils import tmp_to_org
|
2020-11-20 08:12:24 +00:00
|
|
|
from ops.celery.decorator import register_as_period_task
|
2020-09-27 08:02:44 +00:00
|
|
|
from assets.utils import check_node_assets_amount
|
2020-12-10 09:12:39 +00:00
|
|
|
|
|
|
|
from common.utils.lock import AcquireFailed
|
2020-09-27 08:02:44 +00:00
|
|
|
from common.utils import get_logger
|
|
|
|
|
|
|
|
logger = get_logger(__file__)
|
|
|
|
|
|
|
|
|
2020-11-20 12:23:09 +00:00
|
|
|
@shared_task(queue='celery_heavy_tasks')
|
2020-12-10 09:47:35 +00:00
|
|
|
def check_node_assets_amount_task(org_id=Organization.ROOT_ID):
|
2020-12-10 09:12:39 +00:00
|
|
|
try:
|
2020-12-10 09:47:35 +00:00
|
|
|
with tmp_to_org(Organization.get_instance(org_id)):
|
|
|
|
check_node_assets_amount()
|
2020-12-10 09:12:39 +00:00
|
|
|
except AcquireFailed:
|
|
|
|
logger.error(_('The task of self-checking is already running and cannot be started repeatedly'))
|
2020-12-10 09:47:35 +00:00
|
|
|
|
|
|
|
|
|
|
|
@register_as_period_task(crontab='0 2 * * *')
|
|
|
|
@shared_task(queue='celery_heavy_tasks')
|
|
|
|
def check_node_assets_amount_period_task():
|
|
|
|
check_node_assets_amount_task()
|