2022-01-10 11:02:18 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
#
|
|
|
|
from celery import shared_task
|
2022-11-15 08:29:40 +00:00
|
|
|
from django.utils.translation import gettext_lazy as _
|
2022-01-10 11:02:18 +00:00
|
|
|
|
|
|
|
from common.utils import get_object_or_none, get_logger
|
|
|
|
from orgs.utils import tmp_to_org, tmp_to_root_org
|
|
|
|
|
|
|
|
logger = get_logger(__file__)
|
|
|
|
|
|
|
|
|
2023-02-17 09:14:53 +00:00
|
|
|
def task_activity_callback(self, pid, trigger):
|
2023-02-20 10:00:29 +00:00
|
|
|
from accounts.models import AccountBackupAutomation
|
2023-02-17 09:14:53 +00:00
|
|
|
with tmp_to_root_org():
|
|
|
|
plan = get_object_or_none(AccountBackupAutomation, pk=pid)
|
|
|
|
if not plan:
|
|
|
|
return
|
|
|
|
if not plan.latest_execution:
|
|
|
|
return
|
|
|
|
resource_ids = plan.latest_execution.backup_accounts
|
|
|
|
org_id = plan.org_id
|
|
|
|
return resource_ids, org_id
|
|
|
|
|
|
|
|
|
|
|
|
@shared_task(verbose_name=_('Execute account backup plan'), activity_callback=task_activity_callback)
|
2023-02-20 10:00:29 +00:00
|
|
|
def execute_account_backup_task(pid, trigger):
|
2023-02-15 08:48:27 +00:00
|
|
|
from accounts.models import AccountBackupAutomation
|
2022-01-10 11:02:18 +00:00
|
|
|
with tmp_to_root_org():
|
2023-01-16 11:02:09 +00:00
|
|
|
plan = get_object_or_none(AccountBackupAutomation, pk=pid)
|
2022-01-10 11:02:18 +00:00
|
|
|
if not plan:
|
|
|
|
logger.error("No account backup route plan found: {}".format(pid))
|
|
|
|
return
|
|
|
|
with tmp_to_org(plan.org):
|
|
|
|
plan.execute(trigger)
|