diff --git a/cate/util/web/jsonrpcmonitor.py b/cate/util/web/jsonrpcmonitor.py index 5911b056d..627dc9e2f 100644 --- a/cate/util/web/jsonrpcmonitor.py +++ b/cate/util/web/jsonrpcmonitor.py @@ -86,7 +86,7 @@ def start(self, label: str, total_work: float = None): self.label = label self.total = total_work self.worked = 0.0 if total_work else None - self._write_progress(message='Started') + self._write_progress() # first progress method should always be sent self.last_time = None @@ -98,7 +98,7 @@ def progress(self, work: float = None, msg: str = None): def done(self): self.worked = self.total - self._write_progress(message='Done') + self._write_progress() def cancel(self): self._cancelled = True diff --git a/cate/webapi/wsmanag.py b/cate/webapi/wsmanag.py index 8216ccd11..b27531eb8 100644 --- a/cate/webapi/wsmanag.py +++ b/cate/webapi/wsmanag.py @@ -24,9 +24,10 @@ import json import urllib.parse import urllib.request -from tornado import gen, ioloop, websocket from typing import List +from tornado import gen, ioloop, websocket + from cate.conf.defaults import WEBAPI_WORKSPACE_TIMEOUT, WEBAPI_RESOURCE_TIMEOUT, WEBAPI_PLOT_TIMEOUT from cate.core.workspace import Workspace, WorkspaceError, OpKwArgs from cate.core.wsmanag import WorkspaceManager @@ -248,26 +249,36 @@ def _connect(self): @gen.coroutine def _invoke_method(self): self.ws.write_message(self.json_rpc_request) - work_reported = 0 + work_reported = None + started = False while True: response = yield self.ws.read_message() json_response = json.loads(response) - if 'progress' in json_response and self.monitor: - progress = json_response['progress'] - if 'message' in progress: - message = progress['message'] - if message == 'Started': - total = progress.get('total', 100) - label = progress.get('label', '') - self.monitor.start(label, total) - elif message == 'Done': - self.monitor.done() - else: - worked = progress.get('worked', 0) - msg = progress.get('message', '') - self.monitor.progress(worked - work_reported, msg) - work_reported = worked + if 'progress' in json_response: + if self.monitor: + progress = json_response['progress'] + total = progress.get('total') + label = progress.get('label') + worked = progress.get('worked') + msg = progress.get('message') + + if not started: + if total is not None or total is not None: + self.monitor.start(label, total_work=total) + started = True + + if started: + if worked: + if work_reported is None: + work_reported = 0.0 + work = worked - work_reported + work_reported = worked + else: + work = None + self.monitor.progress(work=work, msg=msg) else: + if self.monitor and started: + self.monitor.done() return response def _format_rpc_request(self, method, params): diff --git a/test/core/test_wsmanag.py b/test/core/test_wsmanag.py index 1604a57e5..7ae9c3bf3 100644 --- a/test/core/test_wsmanag.py +++ b/test/core/test_wsmanag.py @@ -138,9 +138,9 @@ def test_resource_progress(self): ('progress', 1.0, 'Step 7 of 10 doing nothing', 70), ('progress', 1.0, 'Step 8 of 10 doing nothing', 80), ('progress', 1.0, 'Step 9 of 10 doing nothing', 90), - ('progress', 1.0, 'Step 10 of 10 doing nothing', 100) - ], rm.records[:11]) - # in ws case 'done' is not transmitted + ('progress', 1.0, 'Step 10 of 10 doing nothing', 100), + ('done',) + ], rm.records) self.del_base_dir(base_dir) def test_session(self):