From 74365ad05e19c4b393ef0265055843eebb80c65f Mon Sep 17 00:00:00 2001 From: Min RK Date: Wed, 21 Mar 2018 16:32:32 +0100 Subject: [PATCH] starting a server updates last_activity and started for user and spawner --- jupyterhub/apihandlers/base.py | 10 +++++----- jupyterhub/user.py | 7 +++++-- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/jupyterhub/apihandlers/base.py b/jupyterhub/apihandlers/base.py index 9193da24..2a91d04e 100644 --- a/jupyterhub/apihandlers/base.py +++ b/jupyterhub/apihandlers/base.py @@ -119,16 +119,16 @@ class APIHandler(BaseHandler): if '' in user.spawners: spawner = user.spawners[''] model['pending'] = spawner.pending or None - if spawner.active and spawner.started: - model['started'] = isoformat(spawner.started) + if spawner.active and spawner.orm_spawner.started: + model['started'] = isoformat(spawner.orm_spawner.started) if self.allow_named_servers: servers = model['servers'] = {} 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: + last_activity = spawner.orm_spawner.last_activity + if last_activity: + last_activity = isoformat(last_activity) servers[name] = s = { 'name': name, 'last_activity': last_activity, diff --git a/jupyterhub/user.py b/jupyterhub/user.py index c8c4ae5f..809b8b56 100644 --- a/jupyterhub/user.py +++ b/jupyterhub/user.py @@ -380,7 +380,10 @@ class User: await maybe_future(authenticator.pre_spawn_start(self, spawner)) 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() # wait for spawner.start to return try: @@ -529,7 +532,7 @@ class User: self.db.delete(orm_token) self.db.commit() finally: - spawner.started = None + spawner.orm_spawner.started = None self.db.commit() # trigger post-spawner hook on authenticator auth = spawner.authenticator