Skip to content

Commit

Permalink
Black run fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
asgibson committed Nov 14, 2024
1 parent 5e9a7e6 commit 3907605
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 33 deletions.
1 change: 0 additions & 1 deletion onair/data_handling/redis_adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
from onair.data_handling.parser_util import extract_meta_data_handle_ss_breakdown



class DataSource(OnAirDataSource):
"""Implements OnAirDataSource interface for receiving data from REDIS servers.
Expand Down
73 changes: 41 additions & 32 deletions redis-experiment-publisher-multi-server.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,25 @@
# When your Redis server requires a password, fill it in here
redis_password = ""
# Connect to Redis
r1 = redis.Redis(host=redis_host,
port=redis_port,
password=redis_password,
decode_responses=True)
r1 = redis.Redis(
host=redis_host, port=redis_port, password=redis_password, decode_responses=True
)

# Initialize the Redis connection for server #1
redis_host = "localhost"
redis_port = 6380
# When your Redis server requires a password, fill it in here
redis_password = ""
# Connect to Redis
r2 = redis.Redis(host=redis_host,
port=redis_port,
password=redis_password,
decode_responses=True)

r2 = redis.Redis(
host=redis_host, port=redis_port, password=redis_password, decode_responses=True
)

# List of channel names
server1_channels = ['state_0']
server2_channels = ['state_1', 'state_2']
server1_channels = ["state_0"]
server2_channels = ["state_1", "state_2"]


# Publish messages on each channel in random order
def publish_messages():
loop_count = 0
Expand All @@ -35,36 +35,45 @@ def publish_messages():
while loop_count < max_loops:
random.shuffle(server1_channels)
for channel in server1_channels:
r1.publish(channel, f'{{"time":{inner_loop_count}, ' \
f'"x":{inner_loop_count+0.1}, ' \
f'"y":{inner_loop_count+0.2}}}')

print(f"Published data to {channel}, " \
f"[{inner_loop_count}, " \
f"{inner_loop_count+0.1}, " \
f"{inner_loop_count+0.2}]")

r1.publish(
channel,
f'{{"time":{inner_loop_count}, '
f'"x":{inner_loop_count+0.1}, '
f'"y":{inner_loop_count+0.2}}}',
)

print(
f"Published data to {channel}, "
f"[{inner_loop_count}, "
f"{inner_loop_count+0.1}, "
f"{inner_loop_count+0.2}]"
)

inner_loop_count += 1
time.sleep(2)

random.shuffle(server2_channels)
for channel in server2_channels:
r2.publish(channel, f'{{"time":{inner_loop_count}, ' \
f'"x":{inner_loop_count+0.1}, ' \
f'"y":{inner_loop_count+0.2}}}')

print(f"Published data to {channel}, " \
f"[{inner_loop_count}, " \
f"{inner_loop_count+0.1}, " \
f"{inner_loop_count+0.2}]")
for channel in server2_channels:
r2.publish(
channel,
f'{{"time":{inner_loop_count}, '
f'"x":{inner_loop_count+0.1}, '
f'"y":{inner_loop_count+0.2}}}',
)

print(
f"Published data to {channel}, "
f"[{inner_loop_count}, "
f"{inner_loop_count+0.1}, "
f"{inner_loop_count+0.2}]"
)

inner_loop_count += 1
time.sleep(2)

loop_count += 1
print(f"Completed {loop_count} loops")



if __name__ == "__main__":
publish_messages()

0 comments on commit 3907605

Please sign in to comment.