Ajusta rabbitmq
This commit is contained in:
13
main.py
13
main.py
@@ -1,6 +1,7 @@
|
||||
import os
|
||||
import pika
|
||||
import json
|
||||
import time
|
||||
from components.video import process_full_video
|
||||
|
||||
RABBITMQ_HOST = os.environ.get('RABBITMQ_HOST', 'rabbitmq')
|
||||
@@ -19,7 +20,7 @@ def publish_to_queue(payload):
|
||||
host=RABBITMQ_HOST,
|
||||
port=RABBITMQ_PORT,
|
||||
credentials=credentials,
|
||||
heartbeat=600,
|
||||
heartbeat=60, # Usando heartbeat menor
|
||||
blocked_connection_timeout=300
|
||||
)
|
||||
connection = pika.BlockingConnection(parameters)
|
||||
@@ -75,12 +76,14 @@ def callback(ch, method, properties, body):
|
||||
ch.basic_ack(delivery_tag=method.delivery_tag)
|
||||
|
||||
def main():
|
||||
while True:
|
||||
try:
|
||||
credentials = pika.PlainCredentials(RABBITMQ_USER, RABBITMQ_PASS)
|
||||
parameters = pika.ConnectionParameters(
|
||||
host=RABBITMQ_HOST,
|
||||
port=RABBITMQ_PORT,
|
||||
credentials=credentials,
|
||||
heartbeat=600,
|
||||
heartbeat=60, # Usando heartbeat menor
|
||||
blocked_connection_timeout=300
|
||||
)
|
||||
connection = pika.BlockingConnection(parameters)
|
||||
@@ -90,6 +93,12 @@ def main():
|
||||
channel.basic_consume(queue=RABBITMQ_QUEUE, on_message_callback=callback)
|
||||
print(' [*] Esperando mensagens. Para sair: CTRL+C')
|
||||
channel.start_consuming()
|
||||
except pika.exceptions.StreamLostError as e:
|
||||
print(f"Conexão perdida: {e}. Reconectando em 5s...")
|
||||
time.sleep(5)
|
||||
except Exception as e:
|
||||
print(f"Erro inesperado: {e}. Reconectando em 5s...")
|
||||
time.sleep(5)
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
||||
Reference in New Issue
Block a user