mirror of https://github.com/jumpserver/jumpserver
parent
1cd551e692
commit
cb82b53791
|
@ -5,7 +5,6 @@ from rest_framework import status, mixins, viewsets
|
|||
|
||||
from orgs.mixins import generics
|
||||
from assets import serializers
|
||||
from assets.const import AutomationTypes
|
||||
from assets.tasks import execute_automation
|
||||
from assets.models import BaseAutomation, AutomationExecution
|
||||
from common.const.choices import Trigger
|
||||
|
@ -111,8 +110,7 @@ class AutomationExecutionViewSet(
|
|||
serializer.is_valid(raise_exception=True)
|
||||
automation = serializer.validated_data.get('automation')
|
||||
tp = serializer.validated_data.get('type')
|
||||
model = AutomationTypes.get_type_model(tp)
|
||||
task = execute_automation.delay(
|
||||
pid=automation.pk, trigger=Trigger.manual, model=model
|
||||
pid=automation.pk, trigger=Trigger.manual, tp=tp
|
||||
)
|
||||
return Response({'task': task.id}, status=status.HTTP_201_CREATED)
|
||||
|
|
|
@ -47,7 +47,7 @@ class BaseAutomation(CommonModelMixin, PeriodTaskModelMixin, OrgModelMixin):
|
|||
def get_register_task(self):
|
||||
name = f"automation_{self.type}_strategy_period_{str(self.id)[:8]}"
|
||||
task = execute_automation.name
|
||||
args = (str(self.id), Trigger.timing, self._meta.model)
|
||||
args = (str(self.id), Trigger.timing, self.type)
|
||||
kwargs = {}
|
||||
return name, task, args, kwargs
|
||||
|
||||
|
|
|
@ -2,12 +2,14 @@ from celery import shared_task
|
|||
|
||||
from orgs.utils import tmp_to_root_org, tmp_to_org
|
||||
from common.utils import get_logger, get_object_or_none
|
||||
from assets.const import AutomationTypes
|
||||
|
||||
logger = get_logger(__file__)
|
||||
|
||||
|
||||
@shared_task(queue='ansible')
|
||||
def execute_automation(pid, trigger, model):
|
||||
def execute_automation(pid, trigger, tp):
|
||||
model = AutomationTypes.get_model(tp)
|
||||
with tmp_to_root_org():
|
||||
instance = get_object_or_none(model, pk=pid)
|
||||
if not instance:
|
||||
|
|
Loading…
Reference in New Issue