Ajusta rabbitmq
This commit is contained in:
13
main.py
13
main.py
@@ -1,6 +1,7 @@
|
|||||||
import os
|
import os
|
||||||
import pika
|
import pika
|
||||||
import json
|
import json
|
||||||
|
import time
|
||||||
from components.video import process_full_video
|
from components.video import process_full_video
|
||||||
|
|
||||||
RABBITMQ_HOST = os.environ.get('RABBITMQ_HOST', 'rabbitmq')
|
RABBITMQ_HOST = os.environ.get('RABBITMQ_HOST', 'rabbitmq')
|
||||||
@@ -19,7 +20,7 @@ def publish_to_queue(payload):
|
|||||||
host=RABBITMQ_HOST,
|
host=RABBITMQ_HOST,
|
||||||
port=RABBITMQ_PORT,
|
port=RABBITMQ_PORT,
|
||||||
credentials=credentials,
|
credentials=credentials,
|
||||||
heartbeat=600,
|
heartbeat=60, # Usando heartbeat menor
|
||||||
blocked_connection_timeout=300
|
blocked_connection_timeout=300
|
||||||
)
|
)
|
||||||
connection = pika.BlockingConnection(parameters)
|
connection = pika.BlockingConnection(parameters)
|
||||||
@@ -75,12 +76,14 @@ def callback(ch, method, properties, body):
|
|||||||
ch.basic_ack(delivery_tag=method.delivery_tag)
|
ch.basic_ack(delivery_tag=method.delivery_tag)
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
while True:
|
||||||
|
try:
|
||||||
credentials = pika.PlainCredentials(RABBITMQ_USER, RABBITMQ_PASS)
|
credentials = pika.PlainCredentials(RABBITMQ_USER, RABBITMQ_PASS)
|
||||||
parameters = pika.ConnectionParameters(
|
parameters = pika.ConnectionParameters(
|
||||||
host=RABBITMQ_HOST,
|
host=RABBITMQ_HOST,
|
||||||
port=RABBITMQ_PORT,
|
port=RABBITMQ_PORT,
|
||||||
credentials=credentials,
|
credentials=credentials,
|
||||||
heartbeat=600,
|
heartbeat=60, # Usando heartbeat menor
|
||||||
blocked_connection_timeout=300
|
blocked_connection_timeout=300
|
||||||
)
|
)
|
||||||
connection = pika.BlockingConnection(parameters)
|
connection = pika.BlockingConnection(parameters)
|
||||||
@@ -90,6 +93,12 @@ def main():
|
|||||||
channel.basic_consume(queue=RABBITMQ_QUEUE, on_message_callback=callback)
|
channel.basic_consume(queue=RABBITMQ_QUEUE, on_message_callback=callback)
|
||||||
print(' [*] Esperando mensagens. Para sair: CTRL+C')
|
print(' [*] Esperando mensagens. Para sair: CTRL+C')
|
||||||
channel.start_consuming()
|
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__":
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
||||||
|
|||||||
Reference in New Issue
Block a user