Skip to content
This repository has been archived by the owner on Aug 29, 2023. It is now read-only.

Commit

Permalink
fixes #353
Browse files Browse the repository at this point in the history
  • Loading branch information
forman committed Sep 18, 2017
1 parent 47ed759 commit 8631b8b
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 22 deletions.
4 changes: 2 additions & 2 deletions cate/util/web/jsonrpcmonitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand Down
45 changes: 28 additions & 17 deletions cate/webapi/wsmanag.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand Down
6 changes: 3 additions & 3 deletions test/core/test_wsmanag.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit 8631b8b

Please sign in to comment.