Files
jumpserver/apps/ops/tasks.py
老广 3d13f3a17d Command (#2134)
* [Update] 任务区分org

* [Update] 修改翻译

* [Update] 使用id而不是hostname

* [Update] 执行命令

* [Update] 修改一些东西

* [Update] 暂存

* [Update] 用户执行命令

* [Update] 添加资产授权模块-tree

* [Update] 暂时这样

* [Update] 批量命令执行

* [Update] 修改表结构

* [Update] 更新翻译

* [Update] 删除cloud模块无效中文翻译
2018-12-10 10:11:54 +08:00

48 lines
1.0 KiB
Python

# coding: utf-8
from celery import shared_task, subtask
from common.utils import get_logger, get_object_or_none
from .models import Task, CommandExecution
logger = get_logger(__file__)
def rerun_task():
pass
@shared_task
def run_ansible_task(tid, callback=None, **kwargs):
"""
:param tid: is the tasks serialized data
:param callback: callback function name
:return:
"""
task = get_object_or_none(Task, id=tid)
if task:
result = task.run()
if callback is not None:
subtask(callback).delay(result, task_name=task.name)
return result
else:
logger.error("No task found")
@shared_task
def run_command_execution(cid, **kwargs):
execution = get_object_or_none(CommandExecution, id=cid)
return execution.run()
@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")