We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 3330f5e commit b649481Copy full SHA for b649481
spug_api/apps/schedule/executors.py
@@ -37,8 +37,7 @@ def host_executor(host, command):
37
return code, round(time.time() - now, 3), out
38
39
40
-def schedule_worker_handler(job):
41
- history_id, host_id, interpreter, command = json.loads(job)
+def dispatch_job(host_id, interpreter, command):
42
if interpreter == 'python':
43
attach = 'INTERPRETER=python\ncommand -v python3 &> /dev/null && INTERPRETER=python3'
44
command = f'{attach}\n$INTERPRETER << EOF\n# -*- coding: UTF-8 -*-\n{command}\nEOF'
@@ -50,6 +49,12 @@ def schedule_worker_handler(job):
50
49
code, duration, out = 1, 0, f'unknown host id for {host_id!r}'
51
else:
52
code, duration, out = host_executor(host, command)
+ return code, duration, out
53
+
54
55
+def schedule_worker_handler(job):
56
+ history_id, host_id, interpreter, command = json.loads(job)
57
+ code, duration, out = dispatch_job(host_id, interpreter, command)
58
59
close_old_connections()
60
with transaction.atomic():
spug_api/apps/schedule/views.py
@@ -7,7 +7,7 @@
7
from apscheduler.triggers.cron import CronTrigger
8
from apps.schedule.scheduler import Scheduler
9
from apps.schedule.models import Task, History
10
-from apps.schedule.executors import local_executor, host_executor
+from apps.schedule.executors import dispatch_job
11
from apps.host.models import Host
12
from django.conf import settings
13
from libs import json_response, JsonParser, Argument, human_datetime, auth
@@ -121,14 +121,7 @@ def post(self, request, t_id):
121
return json_response(error='未找到指定任务')
122
outputs, status = {}, 1
123
for host_id in json.loads(task.targets):
124
- if host_id == 'local':
125
- code, duration, out = local_executor(task.command)
126
- else:
127
- host = Host.objects.filter(pk=host_id).first()
128
- if not host:
129
- code, duration, out = 1, 0, f'unknown host id for {host_id!r}'
130
131
- code, duration, out = host_executor(host, task.command)
+ code, duration, out = dispatch_job(host_id, task.interpreter, task.command)
132
if code != 0:
133
status = 2
134
outputs[host_id] = [code, duration, out]
0 commit comments