starting a server updates last_activity and started for user and spawner

This commit is contained in:
Min RK
2018-03-21 16:32:32 +01:00
parent 9dc24c0995
commit 74365ad05e
2 changed files with 10 additions and 7 deletions

View File

@@ -119,16 +119,16 @@ class APIHandler(BaseHandler):
if '' in user.spawners: if '' in user.spawners:
spawner = user.spawners[''] spawner = user.spawners['']
model['pending'] = spawner.pending or None model['pending'] = spawner.pending or None
if spawner.active and spawner.started: if spawner.active and spawner.orm_spawner.started:
model['started'] = isoformat(spawner.started) model['started'] = isoformat(spawner.orm_spawner.started)
if self.allow_named_servers: if self.allow_named_servers:
servers = model['servers'] = {} servers = model['servers'] = {}
for name, spawner in user.spawners.items(): for name, spawner in user.spawners.items():
last_activity = spawner.orm_spawner.last_activity
if last_activity:
last_activity = isoformat(last_activity)
if spawner.ready: if spawner.ready:
last_activity = spawner.orm_spawner.last_activity
if last_activity:
last_activity = isoformat(last_activity)
servers[name] = s = { servers[name] = s = {
'name': name, 'name': name,
'last_activity': last_activity, 'last_activity': last_activity,

View File

@@ -380,7 +380,10 @@ class User:
await maybe_future(authenticator.pre_spawn_start(self, spawner)) await maybe_future(authenticator.pre_spawn_start(self, spawner))
spawner._start_pending = True spawner._start_pending = True
spawner.started = datetime.utcnow() # update spawner start time, and activity for both spawner and user
self.last_activity = \
spawner.orm_spawner.started = \
spawner.orm_spawner.last_activity = datetime.utcnow()
db.commit() db.commit()
# wait for spawner.start to return # wait for spawner.start to return
try: try:
@@ -529,7 +532,7 @@ class User:
self.db.delete(orm_token) self.db.delete(orm_token)
self.db.commit() self.db.commit()
finally: finally:
spawner.started = None spawner.orm_spawner.started = None
self.db.commit() self.db.commit()
# trigger post-spawner hook on authenticator # trigger post-spawner hook on authenticator
auth = spawner.authenticator auth = spawner.authenticator