Commit 69817fb7 authored by Gottfried Gaisbauer's avatar Gottfried Gaisbauer Committed by Christian Pointner
Browse files

make redis connection data configurable

parent 3b43f9cc
......@@ -69,14 +69,15 @@ class Aura(AuraLogger):
self.scheduler.liquidsoapcommunicator = self.liquidsoapcommunicator
# create the redis adapter
self.messenger = ServerRedisAdapter()
self.messenger.config = self.config
self.messenger = ServerRedisAdapter(self.config)
self.messenger.scheduler = self.scheduler
self.messenger.liquidsoapcommunicator = self.liquidsoapcommunicator
self.diskspace_watcher = DiskSpaceWatcher(self.config, self.logger, self.liquidsoapcommunicator)
self.diskspace_watcher.start()
def receive_signal(signum, stack):
print("received signal")
server.reload()
......
......@@ -34,9 +34,9 @@ class RedisStateStore(object):
"""Store and get Reports from redis"""
def __init__(self, **redis_kwargs):
def __init__(self, config, **redis_kwargs):
"""The default connection parameters are: host='localhost', port=6379, db=0"""
self.db= redis.Redis()
self.db = redis.Redis(host=config.get("redis_host"), port=config.get("redis_port"), db=config.get("redis_db"))
self.channel = '*'
self.section = '*'
self.separator = '_'
......
......@@ -115,10 +115,10 @@ class Padavan:
# ------------------------------------------------------------------------------------------ #
def init_redis_communication(self, with_server=False):
self.redisclient = ClientRedisAdapter()
self.redisclient = ClientRedisAdapter(self.config)
if with_server:
self.redisserver = ServerRedisAdapter()
self.redisserver = ServerRedisAdapter(self.config)
# ------------------------------------------------------------------------------------------ #
def send_redis(self, channel, message):
......
......@@ -51,28 +51,29 @@ class ServerRedisAdapter(threading.Thread, RedisMessenger):
liquidsoapcommunicator = None
# ------------------------------------------------------------------------------------------ #
def __init__(self):
def __init__(self, config):
threading.Thread.__init__(self)
RedisMessenger.__init__(self)
RedisMessenger.__init__(self, config)
# init
threading.Thread.__init__ (self)
#threading.Thread.__init__ (self)
self.config = config
self.shutdown_event = Event()
self.channel = RedisChannel.STANDARD.value
self.section = ''
self.rstore = RedisStateStore()
self.rstore = RedisStateStore(config)
self.errnr = '00'
self.components = {'controller':'01', 'scheduling':'02', 'playd':'03', 'recorder':'04', 'helpers':'09'}
self.fromMail = ''
self.adminMails = ''
self.redisclient = ClientRedisAdapter()
self.redisclient = ClientRedisAdapter(config)
self.connection_tester = ConnectionTester()
# ------------------------------------------------------------------------------------------ #
def run(self):
self.redisdb = redis.Redis()
self.redisdb = redis.Redis(host=self.config.get("redis_host"), port=self.config.get("redis_port"), db=self.config.get("redis_db"))
self.pubsub = self.redisdb.pubsub()
self.pubsub.subscribe(self.channel)
......@@ -109,7 +110,7 @@ class ServerRedisAdapter(threading.Thread, RedisMessenger):
# ------------------------------------------------------------------------------------------ #
def listen_for_one_message(self, channel, socket_timeout=2):
self.redisdb = redis.Redis(socket_timeout=socket_timeout)
self.redisdb = redis.Redis(host=self.config.get("redis_host"), port=self.config.get("redis_port"), db=self.config.get("redis_db"), socket_timeout=socket_timeout)
self.pubsub = self.redisdb.pubsub()
self.pubsub.subscribe(channel)
......@@ -252,8 +253,8 @@ class ServerRedisAdapter(threading.Thread, RedisMessenger):
# ------------------------------------------------------------------------------------------ #
class ClientRedisAdapter(RedisMessenger):
def __init__(self):
RedisMessenger.__init__(self)
def __init__(self, config):
RedisMessenger.__init__(self, config)
# ------------------------------------------------------------------------------------------ #
def publish(self, channel, message):
......
......@@ -43,7 +43,7 @@ class RedisMessenger():
rstore = None
# ------------------------------------------------------------------------------------------ #
def __init__(self):
def __init__(self, config):
super(RedisMessenger, self).__init__()
"""
Constructor
......@@ -51,7 +51,7 @@ class RedisMessenger():
self.logger = logging.getLogger("AuraEngine")
self.channel = RedisChannel.STANDARD
self.section = ''
self.rstore = RedisStateStore()
self.rstore = RedisStateStore(config)
self.errnr = '00'
self.components = {'controller':'01', 'scheduling':'02', 'playd':'03', 'recorder':'04', 'helpers':'09'}
self.fromMail = ''
......
......@@ -40,7 +40,7 @@ from modules.communication.redis.messenger import RedisMessenger
class AuraCalendarService(threading.Thread):
messenger = RedisMessenger()
messenger = None
until = ""
playlistdir = ""
xmlplaylist = range(0)
......@@ -62,6 +62,7 @@ class AuraCalendarService(threading.Thread):
def __init__(self, config, datefrom="", dateto=""):
threading.Thread.__init__(self)
self.config = config
self.messenger = RedisMessenger(config)
self.logger = logging.getLogger("AuraEngine")
self.messenger.set_channel("aura")
......
......@@ -71,7 +71,7 @@ class AuraScheduler(ExceptionLogger, threading.Thread):
Aura Scheduler Class
Gets data from pv and importer, stores and fires events
"""
redismessenger = RedisMessenger()
redismessenger = None
message_timer = []
job_result = {}
......@@ -94,6 +94,7 @@ class AuraScheduler(ExceptionLogger, threading.Thread):
@param config: read engine.ini
"""
self.config = config
self.redismessenger = RedisMessenger(config)
self.logger = logging.getLogger("AuraEngine")
# init threading
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment