Skip to content

Commit

Permalink
Updates addressing PR comments and more
Browse files Browse the repository at this point in the history
Updated Dockerfile to include Redis
Updated multi-server redis publisher to be truly random order of channels
  0 was always first and 1 or 2 random after
  now chooses 0, 1, or 2 in random order (as stated in doc)
Removed original single redis publisher
Updated redis-example doc to be in line with usage of example
  • Loading branch information
asgibson committed Nov 14, 2024
1 parent 3907605 commit 840412a
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 82 deletions.
4 changes: 4 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ RUN \
apt-get install -y python3.11-dev && \
apt-get install -y python3-pip

# Redis
RUN \
apt-get install -y redis

# Add new packages to install here to prevent re-running previous instructions

# Ensure that all packages are up to date after new packages have been added above
Expand Down
26 changes: 16 additions & 10 deletions doc/redis-example.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,30 +25,35 @@ All messages sent must be json format (key to value) and will warn when it is no

## Running the example

If not already running, start a Redis server on 'localhost', port:6379 (typical defaults)
Start a Redis server on 'localhost', port:6379 (typical defaults)
```
redis-server
```

Start a second Redis server on 'localhost', port:6380
```
redis-server --port 6380
```

Start up OnAIR with the redis_example.ini file:
```
python driver.py onair/config/redis_example.ini
```
You should see:
```
Redis Adapter ignoring file
---- Redis adapter connecting to server...
---- ... connected!
---- ... connected to server # 0!
---- Subscribing to channel: state_0
---- Subscribing to channel: state_0 on server # 0
---- Subscribing to channel: state_1
---- Redis adapter: channel 'state_0' received message type: subscribe.
---- Subscribing to channel: state_2
---- ... connected to server # 1!
---- Redis adapter: channel 'state_0' received message type: subscribe.
---- Subscribing to channel: state_1 on server # 1
---- Subscribing to channel: state_2 on server # 1
---- Redis adapter: channel 'state_1' received message type: subscribe.
Expand All @@ -61,9 +66,9 @@ Redis Adapter ignoring file

In another process run the experimental publisher:
```
python redis-experiment-publisher.py
python redis-experiment-publisher-multi-server.py
```
This will send telemetry every 2 seconds, one channel at random until all 3 channels have recieved data then repeat for a total of 9 times (all of which can be changed in the file). Its output should be similar to this:
This will send telemetry every 2 seconds, one channel at random until all 3 channels have recieved data then repeat for a total of 9 times (all of which can be changed in the file). Its output should be similar (but randomly different) to this:
```
Published data to state_0, [0, 0.1, 0.2]
Published data to state_1, [1, 1.1, 1.2]
Expand Down Expand Up @@ -98,4 +103,5 @@ INTERPRETED SYSTEM STATUS: ---
CURRENT DATA: [4, 0.1, 0.2, 4.1, 4.2, 3.1, 3.2]
INTERPRETED SYSTEM STATUS: ---
...
```
37 changes: 10 additions & 27 deletions redis-experiment-publisher-multi-server.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
host=redis_host, port=redis_port, password=redis_password, decode_responses=True
)

# Initialize the Redis connection for server #1
# Initialize the Redis connection for server #2
redis_host = "localhost"
redis_port = 6380
# When your Redis server requires a password, fill it in here
Expand All @@ -22,39 +22,22 @@
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"]

# List of all channels
all_channels = ["state_0", "state_1", "state_2"]

# Publish messages on each channel in random order
def publish_messages():
loop_count = 0
inner_loop_count = 0
max_loops = 9
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}]"
)

inner_loop_count += 1
time.sleep(2)

random.shuffle(server2_channels)
for channel in server2_channels:
r2.publish(
# Shuffle all channels
random.shuffle(all_channels)
for channel in all_channels:
# Choose the appropriate Redis connection based on the channel
r = r1 if channel == "state_0" else r2

r.publish(
channel,
f'{{"time":{inner_loop_count}, '
f'"x":{inner_loop_count+0.1}, '
Expand Down
45 changes: 0 additions & 45 deletions redis-experiment-publisher.py

This file was deleted.

0 comments on commit 840412a

Please sign in to comment.