From 4ac214e91dd0b00145196a2c10bfa36ac68e8a4e Mon Sep 17 00:00:00 2001 From: fit2bot <68588906+fit2bot@users.noreply.github.com> Date: Wed, 15 Feb 2023 16:48:27 +0800 Subject: [PATCH] perf: account task timing not triggered (#9564) Co-authored-by: feng <1304903146@qq.com> --- apps/accounts/models/automations/base.py | 6 +++++- apps/accounts/tasks/backup_account.py | 2 +- apps/assets/models/automations/base.py | 10 +++++++--- apps/ops/mixin.py | 3 ++- 4 files changed, 15 insertions(+), 6 deletions(-) diff --git a/apps/accounts/models/automations/base.py b/apps/accounts/models/automations/base.py index ce45d6a81..30c5df760 100644 --- a/apps/accounts/models/automations/base.py +++ b/apps/accounts/models/automations/base.py @@ -1,6 +1,6 @@ -from django.db import models from django.utils.translation import gettext_lazy as _ +from accounts.tasks import execute_automation from assets.models.automations import ( BaseAutomation as AssetBaseAutomation, AutomationExecution as AssetAutomationExecution @@ -14,6 +14,10 @@ class AccountBaseAutomation(AssetBaseAutomation): proxy = True verbose_name = _("Account automation task") + @property + def execute_task(self): + return execute_automation + @property def execution_model(self): return AutomationExecution diff --git a/apps/accounts/tasks/backup_account.py b/apps/accounts/tasks/backup_account.py index bbcf25d1f..1009ea5b7 100644 --- a/apps/accounts/tasks/backup_account.py +++ b/apps/accounts/tasks/backup_account.py @@ -3,7 +3,6 @@ from celery import shared_task from django.utils.translation import gettext_lazy as _ -from accounts.models import AccountBackupAutomation from common.utils import get_object_or_none, get_logger from orgs.utils import tmp_to_org, tmp_to_root_org @@ -12,6 +11,7 @@ logger = get_logger(__file__) @shared_task(verbose_name=_('Execute account backup plan')) def execute_account_backup_plan(pid, trigger): + from accounts.models import AccountBackupAutomation with tmp_to_root_org(): plan = get_object_or_none(AccountBackupAutomation, pk=pid) if not plan: diff --git a/apps/assets/models/automations/base.py b/apps/assets/models/automations/base.py index e888fdf26..fb3a3fa61 100644 --- a/apps/assets/models/automations/base.py +++ b/apps/assets/models/automations/base.py @@ -4,12 +4,12 @@ from celery import current_task from django.db import models from django.utils.translation import ugettext_lazy as _ -from assets.models.node import Node from assets.models.asset import Asset +from assets.models.node import Node from assets.tasks import execute_automation -from ops.mixin import PeriodTaskModelMixin from common.const.choices import Trigger from common.db.fields import EncryptJsonDictTextField +from ops.mixin import PeriodTaskModelMixin from orgs.mixins.models import OrgModelMixin, JMSOrgBaseModel @@ -47,9 +47,13 @@ class BaseAutomation(PeriodTaskModelMixin, JMSOrgBaseModel): assets = self.get_all_assets().prefetch_related('platform') return assets.group_by_platform() + @property + def execute_task(self): + return execute_automation + def get_register_task(self): name = f"automation_{self.type}_strategy_period_{str(self.id)[:8]}" - task = execute_automation.name + task = self.execute_task.name args = (str(self.id), Trigger.timing, self.type) kwargs = {} return name, task, args, kwargs diff --git a/apps/ops/mixin.py b/apps/ops/mixin.py index 5b706101b..487f677a0 100644 --- a/apps/ops/mixin.py +++ b/apps/ops/mixin.py @@ -1,8 +1,9 @@ # -*- coding: utf-8 -*- # import abc -from django.utils.translation import ugettext_lazy as _ + from django.db import models +from django.utils.translation import ugettext_lazy as _ from rest_framework import serializers from .celery.utils import (