write subscriber map to/ read subscriber map from disk

lowleveltgfilter
Simon 4 years ago
parent 761cd80e88
commit cdef086995
No known key found for this signature in database
GPG Key ID: 6ACF11630B5D8F82

@ -33,6 +33,7 @@ This program currently only works with group voice calls.
# Python modules we need # Python modules we need
import sys import sys
import json
from bitarray import bitarray from bitarray import bitarray
from time import time,sleep,perf_counter from time import time,sleep,perf_counter
import importlib.util import importlib.util
@ -393,6 +394,17 @@ def kaReporting():
elif CONFIG['SYSTEMS'][system]['_bcka'] < time() - 60: elif CONFIG['SYSTEMS'][system]['_bcka'] < time() - 60:
logger.warning('(ROUTER) not sending to system %s as last KeepAlive was %s seconds ago',system, int(time() - CONFIG['SYSTEMS'][system]['_bcka'])) logger.warning('(ROUTER) not sending to system %s as last KeepAlive was %s seconds ago',system, int(time() - CONFIG['SYSTEMS'][system]['_bcka']))
#Write SUB_MAP to disk
def subMapWrite():
_json = json.dumps(SUB_MAP)
try:
_file = open(CONFIG['ALIASES']['SUB_MAP_FILE'],'w')
_file.write(_json)
_file.close()
logger.debug('(SUBSCRIBER) Writing SUB_MAP to disk')
except IOError:
logger.warning('(SUBSCRIBER) Cannot write SUB_MAP to file: IOError')
#Subscriber Map trimmer loop #Subscriber Map trimmer loop
def SubMapTrimmer(): def SubMapTrimmer():
logger.debug('(SUBSCRIBER) Subscriber Map trimmer loop started') logger.debug('(SUBSCRIBER) Subscriber Map trimmer loop started')
@ -405,6 +417,10 @@ def SubMapTrimmer():
for _remove in _remove_list: for _remove in _remove_list:
SUB_MAP.pop(_remove) SUB_MAP.pop(_remove)
subMapWrite()
# run this every 10 seconds to trim stream ids # run this every 10 seconds to trim stream ids
def stream_trimmer_loop(): def stream_trimmer_loop():
@ -2594,6 +2610,7 @@ if __name__ == '__main__':
hblink_handler(_signal, _frame) hblink_handler(_signal, _frame)
logger.info('(GLOBAL) SHUTDOWN: ALL SYSTEM HANDLERS EXECUTED - STOPPING REACTOR') logger.info('(GLOBAL) SHUTDOWN: ALL SYSTEM HANDLERS EXECUTED - STOPPING REACTOR')
reactor.stop() reactor.stop()
subMapWrite()
# Set signal handers so that we can gracefully exit if need be # Set signal handers so that we can gracefully exit if need be
for sig in [signal.SIGINT, signal.SIGTERM]: for sig in [signal.SIGINT, signal.SIGTERM]:
@ -2615,7 +2632,16 @@ if __name__ == '__main__':
BRIDGES = make_bridges(rules_module.BRIDGES) BRIDGES = make_bridges(rules_module.BRIDGES)
#Subscriber map for unit calls - complete with test entry #Subscriber map for unit calls - complete with test entry
SUB_MAP = {bytes_3(73578):('REP-1',1,time())} #SUB_MAP = {bytes_3(73578):('REP-1',1,time())}
SUB_MAP = {}
try:
with open(CONFIG['ALIASES']['SUB_MAP_FILE']) as _json_file:
SUB_MAP = json.load(_json_file)
except:
logger.warning('(SUBSCRIBER) Cannot load SUB_MAP file')
#sys.exit('(SUBSCRIBER) TERMINATING: SUB_MAP file not found or invalid')
#Generator #Generator
generator = {} generator = {}

@ -180,6 +180,7 @@ def build_config(_config_file):
'SUBSCRIBER_URL': config.get(section, 'SUBSCRIBER_URL'), 'SUBSCRIBER_URL': config.get(section, 'SUBSCRIBER_URL'),
'TGID_URL': config.get(section, 'TGID_URL'), 'TGID_URL': config.get(section, 'TGID_URL'),
'STALE_TIME': config.getint(section, 'STALE_DAYS') * 86400, 'STALE_TIME': config.getint(section, 'STALE_DAYS') * 86400,
'SUB_MAP_FILE': config.get(section, 'SUB_MAP_FILE')
}) })
elif section == 'MYSQL': elif section == 'MYSQL':

Loading…
Cancel
Save

Powered by TurnKey Linux.