Skip to content

Commit

Permalink
Add environment variable to control connection heartbeat
Browse files Browse the repository at this point in the history
This patch introduces a new environment variable,
RABBITMQ_HEARTBEAT_SECONDS, that controls the timing of channel
heartbeat. Previously, when generating bundles took more time
than set in the default heartbeat value, the bundle generator had
no chance of returning a successful message due to channel closure
despite successfully generating the bundle. By setting the
RABBITMQ_HEARTBEAT_SECONDS environment variable, we can ensure
that the channel remains open until the bundle generation is
complete, thus allowing the generator to return a successful
message.

Note: The default value of heartbeat that is set when environment
variable is unset (60 seconds) is taken from the Pika documentation.
  • Loading branch information
ppietruszewski-consult-red committed Aug 29, 2023
1 parent 2c296e0 commit 1da80e4
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions bundlegen/rabbitmq/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,12 @@ def start():
connection = pika.BlockingConnection(
pika.ConnectionParameters(host=os.environ.get('RABBITMQ_HOST'),
port=os.environ.get('RABBITMQ_PORT'),
heartbeat=int(os.environ.get('RABBITMQ_HEARTBEAT_SECONDS', 60)),
connection_attempts=3, retry_delay=1))
else:
connection = pika.BlockingConnection(
pika.ConnectionParameters(host=os.environ.get('RABBITMQ_HOST'),
heartbeat=int(os.environ.get('RABBITMQ_HEARTBEAT_SECONDS', 60)),
connection_attempts=3, retry_delay=1))

channel = connection.channel()
Expand Down

0 comments on commit 1da80e4

Please sign in to comment.