From 876ca336c9b44181ebc3abdd35acd285dbf89d68 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=9B=B7=E4=BA=8C=E7=8C=9B?= Date: Fri, 29 Nov 2019 13:53:58 +0800 Subject: [PATCH] A api add schedule time --- spug_api/apps/schedule/executors.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/spug_api/apps/schedule/executors.py b/spug_api/apps/schedule/executors.py index 1b12207..e2aab19 100644 --- a/spug_api/apps/schedule/executors.py +++ b/spug_api/apps/schedule/executors.py @@ -4,25 +4,26 @@ from libs.ssh import SSH from apps.host.models import Host from apps.setting.utils import AppSetting import subprocess +import time def local_executor(q, command): - exit_code, out = -1, None + exit_code, out, now = -1, None, time.time() try: task = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) exit_code = task.wait() out = task.stdout.read() + task.stderr.read() finally: - q.put(('local', exit_code, out.decode())) + q.put(('local', exit_code, time.time() - now, out.decode())) def host_executor(q, host, pkey, command): - exit_code, out = -1, None + exit_code, out, now = -1, None, time.time() try: cli = SSH(host.hostname, host.port, host.username, pkey=pkey) exit_code, out = cli.exec_command(command) finally: - q.put((host.id, exit_code, out.decode())) + q.put((host.id, exit_code, time.time() - now, out.decode())) def dispatch(command, targets):