from celery import Celery from dotenv import load_dotenv import os import torch import random import numpy as np import torch import os import hashlib import sys import uuid from db_models.music import * from db_models.billing import * from db_models.notification import * from db_models.user import * from db_models.data import * os.environ['GOOGLE_APPLICATION_CREDENTIALS'] = 'quick-hangout-422604-e3-5f7544b49207.json' # 환경 변수 로드 load_dotenv() REDIS_PASSWORD = os.getenv('TEST_REDIS_PASSWORD') REDIS_PORT = os.getenv('TEST_REDIS_PORT') REDIS_HOST = os.getenv('TEST_REDIS_HOST') # # 환경 변수에서 Redis 연결 정보 가져오기 # REDIS_PASSWORD = os.getenv('REDIS_PASSWORD') # REDIS_PORT = os.getenv('REDIS_PORT') # REDIS_HOST = os.getenv("REDIS_HOST") common_conf = { 'broker_connection_retry_on_startup': True, # 시작 시 연결 재시도 활성화 'broker_transport_options': { 'max_retries': 5, # 최대 재시도 횟수 'interval_start': 0.1, # 첫 재시도 간격 (초) 'interval_step': 0.2, # 재시도 간격 증가 (초) 'interval_max': 0.5, # 최대 재시도 간격 (초) }, 'broker_connection_timeout': None, # 연결 시간 초과 (초), None으로 설정하여 무제한 'worker_concurrency': 1, # 동시성을 1로 설정 } # 신버전 음원 처리용 Celery 애플리케이션 AI_detection_celery_app = Celery( 'mippia', broker=f'redis://:{REDIS_PASSWORD}@{REDIS_HOST}:{REDIS_PORT}/0', backend=f'redis://:{REDIS_PASSWORD}@{REDIS_HOST}:{REDIS_PORT}/1', ) AI_detection_celery_app.conf.update(common_conf) AI_detection_celery_app.conf.task_routes = {"worker.AI_detection_task": "AI-detection-queue"} AI_detection_celery_app.conf.task_default_queue = "AI-detection-queue" from worker import AI_detection_task # worker에서 태스크를 등록합니다.