2021-02-08 06:59:20 +00:00
|
|
|
from celery import shared_task
|
|
|
|
from django.utils.translation import gettext_lazy as _
|
|
|
|
|
|
|
|
from orgs.models import Organization
|
|
|
|
from orgs.utils import tmp_to_org
|
|
|
|
from ops.celery.decorator import register_as_period_task
|
|
|
|
from assets.utils import check_node_assets_amount
|
|
|
|
|
|
|
|
from common.utils.lock import AcquireFailed
|
|
|
|
from common.utils import get_logger
|
2022-10-10 08:31:45 +00:00
|
|
|
from common.const.crontab import CRONTAB_AT_AM_TWO
|
|
|
|
|
2021-02-08 06:59:20 +00:00
|
|
|
logger = get_logger(__file__)
|
|
|
|
|
|
|
|
|
2022-11-15 08:29:40 +00:00
|
|
|
@shared_task(verbose_name=_('Check the amount of assets under the node'))
|
2021-03-02 06:57:48 +00:00
|
|
|
def check_node_assets_amount_task(org_id=None):
|
|
|
|
if org_id is None:
|
|
|
|
orgs = Organization.objects.all()
|
2021-02-08 06:59:20 +00:00
|
|
|
else:
|
2021-03-02 06:57:48 +00:00
|
|
|
orgs = [Organization.get_instance(org_id)]
|
2021-02-08 06:59:20 +00:00
|
|
|
|
|
|
|
for org in orgs:
|
|
|
|
try:
|
|
|
|
with tmp_to_org(org):
|
|
|
|
check_node_assets_amount()
|
|
|
|
except AcquireFailed:
|
2021-03-02 06:57:48 +00:00
|
|
|
error = _('The task of self-checking is already running '
|
|
|
|
'and cannot be started repeatedly')
|
|
|
|
logger.error(error)
|
2021-02-08 06:59:20 +00:00
|
|
|
|
|
|
|
|
2022-11-15 08:29:40 +00:00
|
|
|
@shared_task(verbose_name=_('Periodic check the amount of assets under the node'))
|
2023-02-17 09:14:53 +00:00
|
|
|
@register_as_period_task(crontab=CRONTAB_AT_AM_TWO)
|
2021-02-08 06:59:20 +00:00
|
|
|
def check_node_assets_amount_period_task():
|
|
|
|
check_node_assets_amount_task()
|