mirror of
https://github.com/jupyterhub/jupyterhub.git
synced 2025-10-13 04:53:01 +00:00
user.py
This commit is contained in:
@@ -33,7 +33,7 @@ from ..metrics import (
|
|||||||
SERVER_SPAWN_DURATION_SECONDS, ServerSpawnStatus,
|
SERVER_SPAWN_DURATION_SECONDS, ServerSpawnStatus,
|
||||||
PROXY_ADD_DURATION_SECONDS, ProxyAddStatus,
|
PROXY_ADD_DURATION_SECONDS, ProxyAddStatus,
|
||||||
SERVER_POLL_DURATION_SECONDS, ServerPollStatus,
|
SERVER_POLL_DURATION_SECONDS, ServerPollStatus,
|
||||||
RUNNING_SERVERS, TOTAL_USERS
|
RUNNING_SERVERS
|
||||||
)
|
)
|
||||||
|
|
||||||
# pattern for the authentication token header
|
# pattern for the authentication token header
|
||||||
@@ -740,7 +740,6 @@ class BaseHandler(RequestHandler):
|
|||||||
spawner._proxy_pending = True
|
spawner._proxy_pending = True
|
||||||
try:
|
try:
|
||||||
await self.proxy.add_user(user, server_name)
|
await self.proxy.add_user(user, server_name)
|
||||||
TOTAL_USERS.inc()
|
|
||||||
|
|
||||||
PROXY_ADD_DURATION_SECONDS.labels(
|
PROXY_ADD_DURATION_SECONDS.labels(
|
||||||
status='success'
|
status='success'
|
||||||
@@ -872,7 +871,6 @@ class BaseHandler(RequestHandler):
|
|||||||
)
|
)
|
||||||
await self.proxy.delete_user(user, server_name)
|
await self.proxy.delete_user(user, server_name)
|
||||||
await user.stop(server_name)
|
await user.stop(server_name)
|
||||||
TOTAL_USERS.dec()
|
|
||||||
|
|
||||||
async def stop_single_user(self, user, server_name=''):
|
async def stop_single_user(self, user, server_name=''):
|
||||||
if server_name not in user.spawners:
|
if server_name not in user.spawners:
|
||||||
|
@@ -17,6 +17,7 @@ from ._version import _check_version, __version__
|
|||||||
from .objects import Server
|
from .objects import Server
|
||||||
from .spawner import LocalProcessSpawner
|
from .spawner import LocalProcessSpawner
|
||||||
from .crypto import encrypt, decrypt, CryptKeeper, EncryptionUnavailable, InvalidToken
|
from .crypto import encrypt, decrypt, CryptKeeper, EncryptionUnavailable, InvalidToken
|
||||||
|
from .metrics import TOTAL_USERS
|
||||||
|
|
||||||
class UserDict(dict):
|
class UserDict(dict):
|
||||||
"""Like defaultdict, but for users
|
"""Like defaultdict, but for users
|
||||||
@@ -39,6 +40,7 @@ class UserDict(dict):
|
|||||||
"""Add a user to the UserDict"""
|
"""Add a user to the UserDict"""
|
||||||
if orm_user.id not in self:
|
if orm_user.id not in self:
|
||||||
self[orm_user.id] = self.from_orm(orm_user)
|
self[orm_user.id] = self.from_orm(orm_user)
|
||||||
|
TOTAL_USERS.inc()
|
||||||
return self[orm_user.id]
|
return self[orm_user.id]
|
||||||
|
|
||||||
def __contains__(self, key):
|
def __contains__(self, key):
|
||||||
@@ -93,6 +95,7 @@ class UserDict(dict):
|
|||||||
self.db.delete(user)
|
self.db.delete(user)
|
||||||
self.db.commit()
|
self.db.commit()
|
||||||
# delete from dict after commit
|
# delete from dict after commit
|
||||||
|
TOTAL_USERS.dec()
|
||||||
del self[user_id]
|
del self[user_id]
|
||||||
|
|
||||||
def count_active_users(self):
|
def count_active_users(self):
|
||||||
|
Reference in New Issue
Block a user