Implement durable image processing pipeline with outbox and recovery
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import os
|
||||
from pathlib import Path
|
||||
|
||||
import pika
|
||||
|
||||
|
||||
QUEUE_NAME = "attachment.process.v1"
|
||||
|
||||
|
||||
def connect_broker():
|
||||
url = Path(os.environ["BROKER_URL_FILE"]).read_text().strip()
|
||||
if not url:
|
||||
raise ValueError("Empty broker URL file")
|
||||
|
||||
parameters = pika.URLParameters(url)
|
||||
parameters.heartbeat = 15
|
||||
parameters.blocked_connection_timeout = 5
|
||||
parameters.socket_timeout = 5
|
||||
parameters.stack_timeout = 10
|
||||
parameters.connection_attempts = 1
|
||||
|
||||
connection = pika.BlockingConnection(parameters)
|
||||
try:
|
||||
channel = connection.channel()
|
||||
channel.queue_declare(
|
||||
queue=QUEUE_NAME,
|
||||
durable=True,
|
||||
exclusive=False,
|
||||
auto_delete=False,
|
||||
)
|
||||
return connection, channel
|
||||
except Exception:
|
||||
connection.close()
|
||||
raise
|
||||
Reference in New Issue
Block a user