Merge branch 'feat'
This commit is contained in:
110
main.py
110
main.py
@@ -1,103 +1,31 @@
|
||||
import os
|
||||
import pika
|
||||
import json
|
||||
import time
|
||||
from components.video import process_full_video
|
||||
import warnings
|
||||
|
||||
RABBITMQ_HOST = os.environ.get('RABBITMQ_HOST', 'rabbitmq')
|
||||
RABBITMQ_PORT = int(os.environ.get('RABBITMQ_PORT', 5672))
|
||||
RABBITMQ_USER = os.environ.get('RABBITMQ_USER', 'admin')
|
||||
RABBITMQ_PASS = os.environ.get('RABBITMQ_PASS')
|
||||
RABBITMQ_QUEUE = os.environ.get('RABBITMQ_QUEUE', 'to-render')
|
||||
RABBITMQ_UPLOAD_QUEUE = os.environ.get('RABBITMQ_UPLOAD_QUEUE', 'to-upload')
|
||||
# Suppress FFmpeg/AV1 warnings for cleaner logs
|
||||
os.environ['OPENCV_FFMPEG_CAPTURE_OPTIONS'] = 'loglevel;quiet'
|
||||
os.environ['OPENCV_LOG_LEVEL'] = 'ERROR'
|
||||
|
||||
if not RABBITMQ_PASS:
|
||||
raise RuntimeError("RABBITMQ_PASS não definido no ambiente")
|
||||
# Suppress MoviePy verbose logging
|
||||
os.environ['PYGAME_HIDE_SUPPORT_PROMPT'] = '1'
|
||||
|
||||
def get_next_message():
|
||||
credentials = pika.PlainCredentials(RABBITMQ_USER, RABBITMQ_PASS)
|
||||
parameters = pika.ConnectionParameters(
|
||||
host=RABBITMQ_HOST,
|
||||
port=RABBITMQ_PORT,
|
||||
credentials=credentials,
|
||||
heartbeat=60,
|
||||
blocked_connection_timeout=300
|
||||
)
|
||||
connection = pika.BlockingConnection(parameters)
|
||||
channel = connection.channel()
|
||||
method_frame, header_frame, body = channel.basic_get(RABBITMQ_QUEUE)
|
||||
if method_frame:
|
||||
channel.basic_ack(method_frame.delivery_tag)
|
||||
connection.close()
|
||||
return body
|
||||
else:
|
||||
connection.close()
|
||||
return None
|
||||
# Filter deprecation warnings
|
||||
warnings.filterwarnings('ignore', category=DeprecationWarning)
|
||||
warnings.filterwarnings('ignore', category=UserWarning, module='moviepy')
|
||||
|
||||
def publish_to_queue(payload):
|
||||
credentials = pika.PlainCredentials(RABBITMQ_USER, RABBITMQ_PASS)
|
||||
parameters = pika.ConnectionParameters(
|
||||
host=RABBITMQ_HOST,
|
||||
port=RABBITMQ_PORT,
|
||||
credentials=credentials,
|
||||
heartbeat=60,
|
||||
blocked_connection_timeout=300
|
||||
)
|
||||
connection = pika.BlockingConnection(parameters)
|
||||
channel = connection.channel()
|
||||
channel.queue_declare(queue=RABBITMQ_UPLOAD_QUEUE, durable=True)
|
||||
channel.basic_publish(
|
||||
exchange='',
|
||||
routing_key=RABBITMQ_UPLOAD_QUEUE,
|
||||
body=json.dumps(payload),
|
||||
properties=pika.BasicProperties(
|
||||
delivery_mode=2, # persistente
|
||||
)
|
||||
)
|
||||
connection.close()
|
||||
from video_render.config import load_settings
|
||||
from video_render.logging_utils import setup_logging
|
||||
from video_render.messaging import RabbitMQWorker
|
||||
from video_render.pipeline import VideoPipeline
|
||||
|
||||
def main():
|
||||
print(' [*] Esperando mensagens. Para sair: CTRL+C')
|
||||
while True:
|
||||
body = get_next_message()
|
||||
if body is None:
|
||||
time.sleep(5)
|
||||
continue
|
||||
|
||||
try:
|
||||
data = json.loads(body)
|
||||
filename = data.get("filename")
|
||||
times = data.get("times", [])
|
||||
url = data.get("url")
|
||||
video_id = data.get("videoId")
|
||||
print(f"Processando vídeo: {filename}")
|
||||
def main() -> None:
|
||||
setup_logging()
|
||||
settings = load_settings()
|
||||
|
||||
processed_files = process_full_video(filename, times)
|
||||
pipeline = VideoPipeline(settings)
|
||||
worker = RabbitMQWorker(settings)
|
||||
worker.consume_forever(pipeline.process_message)
|
||||
|
||||
payload = {
|
||||
"videosProcessedQuantity": len(processed_files),
|
||||
"filename": filename,
|
||||
"processedFiles": processed_files,
|
||||
"url": url,
|
||||
"videoId": video_id,
|
||||
"error": False,
|
||||
}
|
||||
except Exception as e:
|
||||
payload = {
|
||||
"videosProcessedQuantity": 0,
|
||||
"filename": filename if 'filename' in locals() else None,
|
||||
"processedFiles": [],
|
||||
"url": url if 'url' in locals() else None,
|
||||
"videoId": video_id if 'video_id' in locals() else None,
|
||||
"error": str(e),
|
||||
}
|
||||
print(f"Erro no processamento: {e}")
|
||||
|
||||
try:
|
||||
publish_to_queue(payload)
|
||||
print(f"Mensagem publicada na fila '{RABBITMQ_UPLOAD_QUEUE}'.")
|
||||
except Exception as publish_err:
|
||||
print(f"Erro ao publicar na fila '{RABBITMQ_UPLOAD_QUEUE}': {publish_err}")
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
||||
Reference in New Issue
Block a user