mirror of
https://github.com/ail-project/ail-framework.git
synced 2024-11-30 01:37:17 +00:00
chg: [UI dashboard] sort module by name
This commit is contained in:
parent
3bb1bf8d43
commit
c675cb2eaa
2 changed files with 61 additions and 21 deletions
56
bin/lib/queues_modules.py
Executable file
56
bin/lib/queues_modules.py
Executable file
|
@ -0,0 +1,56 @@
|
||||||
|
#!/usr/bin/env python3
|
||||||
|
# -*-coding:UTF-8 -*
|
||||||
|
|
||||||
|
import os
|
||||||
|
import sys
|
||||||
|
import redis
|
||||||
|
import datetime
|
||||||
|
|
||||||
|
sys.path.append(os.path.join(os.environ['AIL_BIN'], 'lib'))
|
||||||
|
import ConfigLoader
|
||||||
|
|
||||||
|
config_loader = ConfigLoader.ConfigLoader()
|
||||||
|
r_serv_queues = config_loader.get_redis_conn("Redis_Queues")
|
||||||
|
config_loader = None
|
||||||
|
|
||||||
|
def get_all_queues_name():
|
||||||
|
return r_serv_queues.hkeys('queues')
|
||||||
|
|
||||||
|
def get_all_queues_dict_with_nb_elem():
|
||||||
|
return r_serv_queues.hgetall('queues')
|
||||||
|
|
||||||
|
def get_all_queues_with_sorted_nb_elem():
|
||||||
|
res = r_serv_queues.hgetall('queues')
|
||||||
|
res = sorted(res.items())
|
||||||
|
return res
|
||||||
|
|
||||||
|
def get_module_pid_by_queue_name(queue_name):
|
||||||
|
return r_serv_queues.smembers('MODULE_TYPE_{}'.format(queue_name))
|
||||||
|
|
||||||
|
# # TODO: remove last msg part
|
||||||
|
def get_module_last_process_start_time(queue_name, module_pid):
|
||||||
|
res = r_serv_queues.get('MODULE_{}_{}'.format(queue_name, module_pid))
|
||||||
|
if res:
|
||||||
|
return res.split(',')[0]
|
||||||
|
return None
|
||||||
|
|
||||||
|
def get_module_last_msg(queue_name, module_pid):
|
||||||
|
return r_serv_queues.get('MODULE_{}_{}_PATH'.format(queue_name, module_pid))
|
||||||
|
|
||||||
|
def get_all_modules_queues_stats():
|
||||||
|
all_modules_queues_stats = []
|
||||||
|
for queue_name, nb_elem_queue in get_all_queues_with_sorted_nb_elem():
|
||||||
|
l_module_pid = get_module_pid_by_queue_name(queue_name)
|
||||||
|
for module_pid in l_module_pid:
|
||||||
|
last_process_start_time = get_module_last_process_start_time(queue_name, module_pid)
|
||||||
|
if last_process_start_time:
|
||||||
|
last_process_start_time = datetime.datetime.fromtimestamp(int(last_process_start_time))
|
||||||
|
seconds = int((datetime.datetime.now() - last_process_start_time).total_seconds())
|
||||||
|
else:
|
||||||
|
seconds = 0
|
||||||
|
all_modules_queues_stats.append((queue_name, nb_elem_queue, seconds, module_pid))
|
||||||
|
return all_modules_queues_stats
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
res = get_all_modules_queues_stats()
|
||||||
|
print(res)
|
|
@ -6,6 +6,7 @@
|
||||||
'''
|
'''
|
||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
|
import sys
|
||||||
import datetime
|
import datetime
|
||||||
import time
|
import time
|
||||||
import flask
|
import flask
|
||||||
|
@ -17,6 +18,9 @@ from flask import Flask, render_template, jsonify, request, Blueprint, url_for
|
||||||
from Role_Manager import login_admin, login_analyst, login_read_only
|
from Role_Manager import login_admin, login_analyst, login_read_only
|
||||||
from flask_login import login_required
|
from flask_login import login_required
|
||||||
|
|
||||||
|
sys.path.append(os.path.join(os.environ['AIL_BIN'], 'lib'))
|
||||||
|
import queues_modules
|
||||||
|
|
||||||
# ============ VARIABLES ============
|
# ============ VARIABLES ============
|
||||||
import Flask_config
|
import Flask_config
|
||||||
|
|
||||||
|
@ -52,27 +56,7 @@ def event_stream():
|
||||||
|
|
||||||
def get_queues(r):
|
def get_queues(r):
|
||||||
# We may want to put the llen in a pipeline to do only one query.
|
# We may want to put the llen in a pipeline to do only one query.
|
||||||
newData = []
|
return queues_modules.get_all_modules_queues_stats()
|
||||||
for queue, card in r.hgetall("queues").items():
|
|
||||||
|
|
||||||
key = "MODULE_" + queue + "_"
|
|
||||||
keySet = "MODULE_TYPE_" + queue
|
|
||||||
|
|
||||||
for moduleNum in r.smembers(keySet):
|
|
||||||
|
|
||||||
value = r.get(key + str(moduleNum))
|
|
||||||
|
|
||||||
if value is not None:
|
|
||||||
timestamp, path = value.split(", ")
|
|
||||||
if timestamp is not None:
|
|
||||||
startTime_readable = datetime.datetime.fromtimestamp(int(timestamp))
|
|
||||||
processed_time_readable = str((datetime.datetime.now() - startTime_readable)).split('.')[0]
|
|
||||||
seconds = int((datetime.datetime.now() - startTime_readable).total_seconds())
|
|
||||||
newData.append( (queue, card, seconds, moduleNum) )
|
|
||||||
else:
|
|
||||||
newData.append( (queue, cards, 0, moduleNum) )
|
|
||||||
|
|
||||||
return newData
|
|
||||||
|
|
||||||
def get_date_range(date_from, num_day):
|
def get_date_range(date_from, num_day):
|
||||||
date = Date(str(date_from[0:4])+str(date_from[4:6]).zfill(2)+str(date_from[6:8]).zfill(2))
|
date = Date(str(date_from[0:4])+str(date_from[4:6]).zfill(2)+str(date_from[6:8]).zfill(2))
|
||||||
|
|
Loading…
Reference in a new issue