U 优化任务计划页面上可以得到更多错误信息

pull/103/head
vapao 2020-06-02 11:27:16 +08:00
parent 77669dd5a5
commit 0e98c1553e
1 changed files with 8 additions and 2 deletions

View File

@ -3,11 +3,12 @@
# Released under the MIT License.
from queue import Queue
from threading import Thread
from libs.ssh import SSH
from libs.ssh import SSH, AuthenticationException
from apps.host.models import Host
from apps.setting.utils import AppSetting
from django.db import close_old_connections
import subprocess
import socket
import time
@ -26,8 +27,13 @@ def host_executor(q, host, pkey, command):
try:
cli = SSH(host.hostname, host.port, host.username, pkey=pkey)
exit_code, out = cli.exec_command(command)
out = out.decode() if out else None
except AuthenticationException:
out = 'ssh authentication fail'
except socket.error as e:
out = f'network error {e}'
finally:
q.put((host.id, exit_code, round(time.time() - now, 3), out.decode() if out else None))
q.put((host.id, exit_code, round(time.time() - now, 3), out))
def dispatch(command, targets):