-
Notifications
You must be signed in to change notification settings - Fork 832
/
views.py
41 lines (33 loc) · 1.06 KB
/
views.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
"""
Update the list of connected user. This need a communication between the worker
process and the root process.
"""
import os
from jadi import component
from aj.api.http import get, HttpPlugin
# from aj.auth import authorize
from aj.api.endpoint import endpoint
import aj
import gevent
@component(HttpPlugin)
class Handler(HttpPlugin):
def __init__(self, context):
self.context = context
@get(r'/api/session_list/sessions')
@endpoint(api=True)
def handle_api_list_sessions(self, http_context):
"""
Send an update request from the worker process to the root process in
order to get an actual list of connected users and their details,
stored in the var aj.sessions.
:param http_context: HttpContext
:type http_context: HttpContext
:return: Dict of Session obj
:rtype: dict
"""
if os.getuid() != 0:
http_context.respond_forbidden()
return ''
self.context.worker.update_sessionlist()
gevent.sleep(1)
return aj.sessions