Commit 44f8b978 authored by ibuler's avatar ibuler

[Update] 添加failover ws

parent 1a82b858
......@@ -24,6 +24,8 @@
var port = document.location.port ? ":" + document.location.port : "";
var url = "/ws/ops/tasks/" + "{{ task_id }}" + "/log/";
var wsURL = scheme + "://" + document.location.hostname + port + url;
var failOverPort = "{{ ws_port }}";
var failOverWsURL = scheme + "://" + document.location.hostname + ':' + failOverPort + url;
var term;
var ws;
......@@ -38,13 +40,21 @@
});
term.open(document.getElementById('term'));
term.resize(120, 30);
ws = new WebSocket(wsURL);
ws.onmessage = function(e) {
var data = JSON.parse(e.data);
term.write(data.message);
};
ws.onerror = function (e) {
term.write("Connect websocket server error")
ws = new WebSocket(failOverWsURL);
ws.onmessage = function(e) {
var data = JSON.parse(e.data);
term.write(data.message);
};
ws.onerror = function (e) {
term.write("Connect websocket server error")
}
}
});
</script>
# -*- coding: utf-8 -*-
#
from django.views.generic import TemplateView
from django.conf import settings
from common.permissions import PermissionsMixin, IsOrgAdmin, IsOrgAuditor
......@@ -14,5 +15,8 @@ class CeleryTaskLogView(PermissionsMixin, TemplateView):
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context.update({'task_id': self.kwargs.get('pk')})
context.update({
'task_id': self.kwargs.get('pk'),
'ws_port': settings.CONFIG.WS_LISTEN_PORT
})
return context
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment