fix issues

pull/410/head
vapao 2021-09-07 23:24:03 +08:00
parent 0fb6a05431
commit 63c534e40c
5 changed files with 25 additions and 14 deletions

View File

@ -14,9 +14,9 @@ def exec_worker_handler(job):
class Job:
def __init__(self, hostname, port, username, pkey, command, token=None):
def __init__(self, key, hostname, port, username, pkey, command, token=None):
self.ssh = SSH(hostname, port, username, pkey)
self.key = f'{hostname}:{port}'
self.key = key
self.command = command
self.token = token
self.rds_cli = None

View File

@ -56,6 +56,7 @@ def do_task(request):
token, rds = uuid.uuid4().hex, get_redis_connection()
for host in Host.objects.filter(id__in=form.host_ids):
data = dict(
key=host.id,
token=token,
hostname=host.hostname,
port=host.port,

View File

@ -37,6 +37,9 @@ class ExecConsole extends React.Component {
const protocol = window.location.protocol === 'https:' ? 'wss:' : 'ws:';
this.socket = new WebSocket(`${protocol}//${window.location.host}/api/ws/exec/${store.token}/?x-token=${X_TOKEN}`);
this.socket.onopen = () => {
for (let key of Object.keys(store.outputs)) {
this.handleWrite(key, '\x1b[36m### Waiting for scheduling ...\x1b[0m\r\n')
}
this.socket.send('ok');
};
this.socket.onmessage = e => {
@ -46,13 +49,7 @@ class ExecConsole extends React.Component {
const {key, data, status} = JSON.parse(e.data);
if (status !== undefined) store.outputs[key].status = status;
if (data) {
if (this.terms[key]) {
this.terms[key].write(data)
} else if (this.outputs[key]) {
this.outputs[key] += data
} else {
this.outputs[key] = data
}
this.handleWrite(key, data)
}
}
};
@ -60,9 +57,9 @@ class ExecConsole extends React.Component {
for (let key of Object.keys(store.outputs)) {
store.outputs[key]['status'] = 'websocket error'
if (this.terms[key]) {
this.terms[key].write('\u001b[31mWebsocket connection failed!\u001b[0m')
this.terms[key].write('\x1b[31mWebsocket connection failed!\x1b[0m')
} else {
this.outputs[key] = '\u001b[31mWebsocket connection failed!\u001b[0m'
this.outputs[key] = '\x1b[31mWebsocket connection failed!\x1b[0m'
}
}
}
@ -73,6 +70,16 @@ class ExecConsole extends React.Component {
store.isFullscreen = false;
}
handleWrite = (key, data) => {
if (this.terms[key]) {
this.terms[key].write(data)
} else if (this.outputs[key]) {
this.outputs[key] += data
} else {
this.outputs[key] = data
}
}
genExtra = (status) => {
if (status === -2) {
return <LoadingOutlined style={{fontSize: 20, color: '#108ee9'}}/>;

View File

@ -24,6 +24,10 @@ class TaskIndex extends React.Component {
}
}
componentWillUnmount() {
store.host_ids = []
}
handleSubmit = () => {
this.setState({loading: true});
const host_ids = store.host_ids;

View File

@ -29,9 +29,8 @@ class Store {
} else {
for (let id of this.host_ids) {
const host = hostStore.idMap[id];
const key = `${host.hostname}:${host.port}`;
this.outputs[key] = {
title: `${host.name}(${key})`,
this.outputs[host.id] = {
title: `${host.name}(${host.hostname}:${host.port})`,
status: -2
}
}