mirror of
https://github.com/jupyterhub/jupyterhub.git
synced 2025-10-13 04:53:01 +00:00
add user.created, spawner.started
- alembic revision - in user/spawner models
This commit is contained in:
@@ -18,7 +18,6 @@ import sqlalchemy as sa
|
||||
|
||||
def upgrade():
|
||||
tables = op.get_bind().engine.table_names()
|
||||
op.add_column('users', sa.Column('created', sa.DateTime(), nullable=True))
|
||||
op.add_column('api_tokens', sa.Column('created', sa.DateTime(), nullable=True))
|
||||
op.add_column('api_tokens', sa.Column('last_activity', sa.DateTime(), nullable=True))
|
||||
op.add_column('api_tokens', sa.Column('note', sa.Unicode(length=1023), nullable=True))
|
||||
@@ -32,7 +31,6 @@ def upgrade():
|
||||
def downgrade():
|
||||
op.drop_constraint(None, 'oauth_codes', type_='foreignkey')
|
||||
op.drop_constraint(None, 'oauth_access_tokens', type_='foreignkey')
|
||||
op.add_column('users', 'created')
|
||||
op.drop_column('oauth_access_tokens', 'last_activity')
|
||||
op.drop_column('oauth_access_tokens', 'created')
|
||||
op.drop_column('api_tokens', 'note')
|
||||
|
47
jupyterhub/alembic/versions/99a28a4418e1_user_created.py
Normal file
47
jupyterhub/alembic/versions/99a28a4418e1_user_created.py
Normal file
@@ -0,0 +1,47 @@
|
||||
"""user.created and spawner.started
|
||||
|
||||
Revision ID: 99a28a4418e1
|
||||
Revises: 56cc5a70207e
|
||||
Create Date: 2018-03-21 14:27:17.466841
|
||||
|
||||
"""
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = '99a28a4418e1'
|
||||
down_revision = '56cc5a70207e'
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
|
||||
from datetime import datetime
|
||||
|
||||
def upgrade():
|
||||
op.add_column('users', sa.Column('created', sa.DateTime, nullable=True))
|
||||
c = op.get_bind()
|
||||
# fill created date with current time
|
||||
now = datetime.utcnow()
|
||||
c.execute("""
|
||||
UPDATE users
|
||||
SET created='%s'
|
||||
""" % (now,)
|
||||
)
|
||||
|
||||
tables = c.engine.table_names()
|
||||
|
||||
if 'spawners' in tables:
|
||||
op.add_column('spawners', sa.Column('started', sa.DateTime, nullable=True))
|
||||
# fill started value with now for running servers
|
||||
c.execute("""
|
||||
UPDATE spawners
|
||||
SET started='%s'
|
||||
WHERE server_id NOT NULL
|
||||
""" % (now,)
|
||||
)
|
||||
|
||||
|
||||
def downgrade():
|
||||
op.drop_column('users', 'created')
|
||||
op.drop_column('spawners', 'started')
|
@@ -112,10 +112,15 @@ class APIHandler(BaseHandler):
|
||||
'groups': [ g.name for g in user.groups ],
|
||||
'server': user.url if user.running else None,
|
||||
'pending': None,
|
||||
'created': isoformat(user.created),
|
||||
'last_activity': last_activity,
|
||||
'started': None,
|
||||
}
|
||||
if '' in user.spawners:
|
||||
model['pending'] = user.spawners[''].pending or None
|
||||
spawner = user.spawners['']
|
||||
model['pending'] = spawner.pending or None
|
||||
if spawner.active and spawner.started:
|
||||
model['started'] = isoformat(spawner.started)
|
||||
|
||||
if self.allow_named_servers:
|
||||
servers = model['servers'] = {}
|
||||
@@ -127,6 +132,7 @@ class APIHandler(BaseHandler):
|
||||
servers[name] = s = {
|
||||
'name': name,
|
||||
'last_activity': last_activity,
|
||||
'started': isoformat(spawner.orm_spawner.started),
|
||||
}
|
||||
if spawner.pending:
|
||||
s['pending'] = spawner.pending
|
||||
|
@@ -183,6 +183,7 @@ class Spawner(Base):
|
||||
state = Column(JSONDict)
|
||||
name = Column(Unicode(255))
|
||||
|
||||
started = Column(DateTime)
|
||||
last_activity = Column(DateTime, nullable=True)
|
||||
|
||||
|
||||
|
@@ -380,6 +380,8 @@ class User:
|
||||
await maybe_future(authenticator.pre_spawn_start(self, spawner))
|
||||
|
||||
spawner._start_pending = True
|
||||
spawner.started = datetime.utcnow()
|
||||
db.commit()
|
||||
# wait for spawner.start to return
|
||||
try:
|
||||
# run optional preparation work to bootstrap the notebook
|
||||
@@ -527,6 +529,8 @@ class User:
|
||||
self.db.delete(orm_token)
|
||||
self.db.commit()
|
||||
finally:
|
||||
spawner.started = None
|
||||
self.db.commit()
|
||||
# trigger post-spawner hook on authenticator
|
||||
auth = spawner.authenticator
|
||||
try:
|
||||
|
Reference in New Issue
Block a user