Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
HayleyO committed Aug 7, 2024
2 parents c268fb6 + 291e1b3 commit 1eb3f45
Show file tree
Hide file tree
Showing 2 changed files with 242 additions and 225 deletions.
44 changes: 24 additions & 20 deletions onair/data_handling/redis_adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,28 +64,32 @@ def connect(self):
password = server_config['password']
else:
password = ''

#if there are subscriptions in this Redis server configuration's subscription key
if len(server_config['subscriptions']) != 0:
#Create the servers and append them to self.servers list
self.servers.append(redis.Redis(address, port, db, password))

self.servers.append(redis.Redis(address, port, db, password))
try:
#Ping server to make sure we can connect
self.servers[-1].ping()
print_msg(f'... connected to server # {idx}!')

if self.servers[-1].ping():
print_msg(f'... connected to server # {idx}!')
else:
print_msg(f'Did not connect to server # {idx}', 'RED')

#if there are subscriptions in this Redis server configuration's subscription key
if len(server_config['subscriptions']) !=0:
#Set up Redis pubsub function for the current server
pubsub = self.servers[-1].pubsub()
#Set up Redis pubsub function for the current server
pubsub = self.servers[-1].pubsub()

for s in server_config['subscriptions']:
pubsub.subscribe(s)
print_msg(f"Subscribing to channel: {s} on server # {idx}")
for s in server_config['subscriptions']:
pubsub.subscribe(s)
print_msg(f"Subscribing to channel: {s} on server # {idx}")
listen_thread = threading.Thread(target=self.message_listener, args=(pubsub,))
listen_thread.start()

listen_thread = threading.Thread(target=self.message_listener, args=(pubsub,))
listen_thread.start()
else:
print_msg(f"No subscriptions given!")
#This except will be hit if self.servers[-1].ping() threw an exception (could not properly ping server)
except:
print_msg(f'Did not connect to server # {idx}. Not setting up subscriptions.', 'RED')

else:
print_msg("No subscriptions given! Redis server not created")

def parse_meta_data_file(self, meta_data_file, ss_breakdown):
self.server_configs = []
Expand All @@ -95,15 +99,15 @@ def parse_meta_data_file(self, meta_data_file, ss_breakdown):
keys = meta.keys()

# Setup redis server configuration
#Checking in 'redis' exists
#Checking if 'redis' exists
if 'redis' in keys:
count_server_config = 0
#Checking if dictionaries within 'redis' key each have a 'subscription' key. Error will be thrown if not.
for server_config in meta['redis']:
redis_config_keys = server_config.keys()
if 'subscriptions' in redis_config_keys == False:
if ('subscriptions' in redis_config_keys) == False:
raise ConfigKeyError(f'Config file: \'{meta_data_file}\' ' \
f'missing required key \'suscriptions\' from {count_server_config} in key \'redis\' ')
f'missing required key \'subscriptions\' from {count_server_config} in key \'redis\'')
count_server_config +=1

#Saving all of Redis dictionaries from JSON file to self.server_configs
Expand Down
Loading

0 comments on commit 1eb3f45

Please sign in to comment.