Compare commits

..

No commits in common. "eea090d2654475670ba585cf1b5d426c21ddf4ae" and "573a8e57bcfa9140c509aea7d2b063ba104d8f6d" have entirely different histories.

4 changed files with 23 additions and 58 deletions

View file

@ -295,17 +295,6 @@ class CentralManagement():
self.currentHit.open_page_at = datetime.datetime.utcnow()
self.store.saveHIT(self.currentHit)
self.setLight(True)
elif signal.name == 'server.close':
if not signal.params['abandoned']:
continue
a = self.currentHit.getLastAssignment()
if a.assignment_id != signal.params['assignment_id']:
self.logger.info(f"Close of older assignment_id: {signal}")
continue
self.logger.critical(f"Websocket closed of active assignment_id: {signal}")
a.abandoned_at = datetime.datetime.utcnow()
self.store.saveAssignment(a)
self.plotter.park()
elif signal.name == 'assignment.submit':
a = self.currentHit.getLastAssignment()
if a.assignment_id != signal.params['assignment_id']:

View file

@ -56,8 +56,6 @@ class WebSocketHandler(tornado.websocket.WebSocketHandler):
self.plotterQ = plotterQ
self.eventQ = eventQ
self.store = store
self.assignment_id = None
self.abandoned = False
def check_origin(self, origin):
parsed_origin = urlparse(origin)
@ -81,8 +79,7 @@ class WebSocketHandler(tornado.websocket.WebSocketHandler):
if self.assignment.assignment_id != self.assignment_id:
raise Exception(f"Opening websocket for invalid assignment {self.assignment_id}")
self.timeout = self.assignment.created_at + datetime.timedelta(seconds=self.store.getHitTimeout())
# timeLeft = (self.timeout - datetime.datetime.utcnow()).total_seconds()
self.timeout = datetime.datetime.now() + datetime.timedelta(seconds=self.store.getHitTimeout())
if self.hit.isSubmitted():
raise Exception("Opening websocket for already submitted hit")
@ -90,8 +87,7 @@ class WebSocketHandler(tornado.websocket.WebSocketHandler):
#logger.info(f"New client connected: {self.request.remote_ip} for {self.hit.id}/{self.hit.hit_id}")
self.eventQ.put(Signal('server.open', dict(assignment_id=self.assignment_id)))
self.strokes = []
# the client sent the message
def on_message(self, message):
@ -101,7 +97,7 @@ class WebSocketHandler(tornado.websocket.WebSocketHandler):
logger.critical(f"Skip message for non-last assignment {message}")
return
if datetime.datetime.utcnow() > self.timeout:
if datetime.datetime.now() > self.timeout:
logger.critical("Close websocket after timeout (abandon?)")
self.close()
return
@ -168,9 +164,6 @@ class WebSocketHandler(tornado.websocket.WebSocketHandler):
# client disconnected
def on_close(self):
self.__class__.rmConnection(self)
if self.assignment_id:
self.eventQ.put(Signal('server.close', dict(assignment_id=self.assignment_id, abandoned=self.abandoned)))
logger.info(f"Client disconnected: {self.request.remote_ip}")
# TODO: abandon assignment??
@ -213,20 +206,6 @@ class WebSocketHandler(tornado.websocket.WebSocketHandler):
if client not in cls.connections:
return
cls.connections.remove(client)
@classmethod
def hasConnection(cls, client):
return client in cls.connections
@classmethod
def timeoutConnectionForAssignment(cls, assignment_id):
logger.warn(f"Check timeout for {assignment_id}")
for client in cls.connections:
logger.info(client.assignment_id)
if client.assignment_id == assignment_id:
client.abandoned = True
client.close()
class StatusWebSocketHandler(tornado.websocket.WebSocketHandler):
@ -332,8 +311,6 @@ class DrawPageHandler(tornado.web.RequestHandler):
logger.warning(f"Create new assignment {assignmentId}")
assignment = self.store.newAssignment(self.store.currentHit, assignmentId)
self.store.saveAssignment(assignment)
logger.info(f"Set close timeout for {self.store.getHitTimeout()}")
Server.loop.asyncio_loop.call_later(self.store.getHitTimeout(), WebSocketHandler.timeoutConnectionForAssignment, assignment.assignment_id)
previous_hit = self.store.getLastSubmittedHit()
if not previous_hit:
@ -455,6 +432,7 @@ class StatusPage():
return [hit.toDict() for hit in hits]
class Server:
"""
Server for HIT -> plotter events

View file

@ -5,11 +5,11 @@
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
width="210mm"
height="210mm"
viewBox="0 0 210 210"
id="svg8"
version="1.1"
id="svg8">
viewBox="0 0 210 210"
height="210mm"
width="210mm">
<defs
id="defs2" />
<metadata
@ -25,15 +25,14 @@
</rdf:RDF>
</metadata>
<g
style="stroke-width:1.52441633"
id="layer1"
transform="matrix(0.65598879,0,0,0.65598879,44.11553,-86.509667)">
transform="translate(0,-87)"
id="layer1">
<rect
style="fill:none;fill-opacity:1;stroke:#ffffff;stroke-width:1.52441633;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0.75590557;stroke-opacity:1"
id="rect815"
width="107.34524"
height="107.34524"
y="138.32738"
x="51.327381"
y="138.32738" />
height="107.34524"
width="107.34524"
id="rect815"
style="fill:none;fill-opacity:1;stroke:white;stroke-width:1;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0.75590557;stroke-opacity:1" />
</g>
</svg>

Before

Width:  |  Height:  |  Size: 1.1 KiB

After

Width:  |  Height:  |  Size: 1 KiB

View file

@ -13,7 +13,7 @@
height="180mm"
preserveAspectRatio="none"
id="svg3"
sodipodi:docname="basic_square.svg"
sodipodi:docname="000139.svg"
inkscape:version="0.92.4 (5da689c313, 2019-01-14)">
<metadata
id="metadata9">
@ -37,23 +37,22 @@
guidetolerance="10"
inkscape:pageopacity="0"
inkscape:pageshadow="2"
inkscape:window-width="3840"
inkscape:window-height="2160"
inkscape:window-width="3836"
inkscape:window-height="2126"
id="namedview5"
showgrid="false"
inkscape:zoom="1.3875926"
inkscape:cx="-14.783892"
inkscape:cx="311.32047"
inkscape:cy="589.76197"
inkscape:window-x="0"
inkscape:window-y="0"
inkscape:window-x="2"
inkscape:window-y="32"
inkscape:window-maximized="1"
inkscape:current-layer="svg3"
showguides="false" />
inkscape:current-layer="svg3" />
<rect
style="fill:none;fill-opacity:1;stroke:#808080;stroke-width:4;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0.75590557;stroke-opacity:1"
id="rect819"
width="306.99152"
height="306.99152"
x="1287.0762"
y="165.88982" />
y="638.77118" />
</svg>

Before

Width:  |  Height:  |  Size: 1.7 KiB

After

Width:  |  Height:  |  Size: 1.7 KiB