mirror of
https://github.com/jumpserver/jumpserver.git
synced 2025-10-13 04:05:12 +00:00
[Update] 修改 task 运行机制
This commit is contained in:
@@ -1,6 +1,10 @@
|
||||
# coding: utf-8
|
||||
from celery import shared_task
|
||||
from django.core import serializers
|
||||
from celery import shared_task, subtask
|
||||
|
||||
from common.utils import get_logger, get_object_or_none
|
||||
from .models import Task
|
||||
|
||||
logger = get_logger(__file__)
|
||||
|
||||
|
||||
def rerun_task():
|
||||
@@ -8,6 +12,31 @@ def rerun_task():
|
||||
|
||||
|
||||
@shared_task
|
||||
def run_task(tasks_json):
|
||||
for task in serializers.deserialize('json', tasks_json):
|
||||
task.object.run()
|
||||
def run_ansible_task(task_id, callback=None, **kwargs):
|
||||
"""
|
||||
:param task_id: is the tasks serialized data
|
||||
:param callback: callback function name
|
||||
:return:
|
||||
"""
|
||||
|
||||
task = get_object_or_none(Task, id=task_id)
|
||||
if task:
|
||||
result = task.object.run()
|
||||
if callback is not None:
|
||||
subtask(callback).delay(result)
|
||||
return result
|
||||
else:
|
||||
logger.error("No task found")
|
||||
|
||||
|
||||
@shared_task
|
||||
def hello(name, callback=None):
|
||||
print("Hello {}".format(name))
|
||||
if callback is not None:
|
||||
subtask(callback).delay("Guahongwei")
|
||||
|
||||
|
||||
@shared_task
|
||||
def hello_callback(result):
|
||||
print(result)
|
||||
print("Hello callback")
|
||||
|
Reference in New Issue
Block a user