mirror of https://github.com/openspug/spug
F fix issue
parent
43dc8eeca1
commit
79ef2c46a9
|
@ -58,7 +58,9 @@ def host_executor(host, command):
|
||||||
return False, f'异常信息:{e}'
|
return False, f'异常信息:{e}'
|
||||||
|
|
||||||
|
|
||||||
def dispatch(tp, addr, extra):
|
def dispatch(tp, addr, extra, in_view=False):
|
||||||
|
if not in_view:
|
||||||
|
close_old_connections()
|
||||||
if tp == '1':
|
if tp == '1':
|
||||||
return site_check(addr)
|
return site_check(addr)
|
||||||
elif tp == '2':
|
elif tp == '2':
|
||||||
|
@ -71,6 +73,5 @@ def dispatch(tp, addr, extra):
|
||||||
command = extra
|
command = extra
|
||||||
else:
|
else:
|
||||||
raise TypeError(f'invalid monitor type: {tp!r}')
|
raise TypeError(f'invalid monitor type: {tp!r}')
|
||||||
close_old_connections()
|
|
||||||
host = Host.objects.filter(pk=addr).first()
|
host = Host.objects.filter(pk=addr).first()
|
||||||
return host_executor(host, command)
|
return host_executor(host, command)
|
||||||
|
|
|
@ -88,6 +88,6 @@ def run_test(request):
|
||||||
Argument('extra', required=False)
|
Argument('extra', required=False)
|
||||||
).parse(request.body)
|
).parse(request.body)
|
||||||
if error is None:
|
if error is None:
|
||||||
is_success, message = dispatch(form.type, form.addr, form.extra)
|
is_success, message = dispatch(form.type, form.addr, form.extra, True)
|
||||||
return json_response({'is_success': is_success, 'message': message})
|
return json_response({'is_success': is_success, 'message': message})
|
||||||
return json_response(error=error)
|
return json_response(error=error)
|
||||||
|
|
|
@ -35,13 +35,14 @@ def host_executor(q, host, command):
|
||||||
q.put((host.id, exit_code, round(time.time() - now, 3), out))
|
q.put((host.id, exit_code, round(time.time() - now, 3), out))
|
||||||
|
|
||||||
|
|
||||||
def dispatch(command, targets):
|
def dispatch(command, targets, in_view=False):
|
||||||
|
if not in_view:
|
||||||
|
close_old_connections()
|
||||||
threads, q = [], Queue()
|
threads, q = [], Queue()
|
||||||
for t in targets:
|
for t in targets:
|
||||||
if t == 'local':
|
if t == 'local':
|
||||||
threads.append(Thread(target=local_executor, args=(q, command)))
|
threads.append(Thread(target=local_executor, args=(q, command)))
|
||||||
elif isinstance(t, int):
|
elif isinstance(t, int):
|
||||||
close_old_connections()
|
|
||||||
host = Host.objects.filter(pk=t).first()
|
host = Host.objects.filter(pk=t).first()
|
||||||
if not host:
|
if not host:
|
||||||
raise ValueError(f'unknown host id: {t!r}')
|
raise ValueError(f'unknown host id: {t!r}')
|
||||||
|
|
|
@ -110,7 +110,7 @@ class HistoryView(View):
|
||||||
task = Task.objects.filter(pk=t_id).first()
|
task = Task.objects.filter(pk=t_id).first()
|
||||||
if not task:
|
if not task:
|
||||||
return json_response(error='未找到指定任务')
|
return json_response(error='未找到指定任务')
|
||||||
data = dispatch(task.command, json.loads(task.targets))
|
data = dispatch(task.command, json.loads(task.targets), True)
|
||||||
score = 0
|
score = 0
|
||||||
for item in data:
|
for item in data:
|
||||||
score += 1 if item[1] else 0
|
score += 1 if item[1] else 0
|
||||||
|
|
Loading…
Reference in New Issue