-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathheartbeat.py
40 lines (32 loc) · 1.16 KB
/
heartbeat.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
"""
omsserver heartbeat.py
:copyright: (c) 2019 by Pavel Konovalov
Created on 26/08/2019
"""
import time
from helper_database import cursor_to_json
from user import get_item as get_user_by_session_key
def status(db, session_key):
"""
Возвращает статус сервера, валидность ключа авторизации, метки времени создания слоев
:param db:
:param session_key:
:return:
"""
server_timezone = time.timezone / 3600.0
session_key_status = 'invalid'
cursor = db.cursor()
sql = 'select id, time_stamp as ts from gis_layer where enabled_for_mobile = 1'
cursor.execute(sql)
layers = cursor_to_json(cursor)
server_status = {'status': 'ok',
'timezone': server_timezone,
'time': time.ctime(),
'layers': layers,
'session_key': session_key_status
}
if session_key is not None:
server_status['session_key'] = 'valid'
server_status['user'] = get_user_by_session_key(db, session_key, None)
return server_status