import time
from redis.lock import Lock
import logging

QUEUE_NAME = 'task_queue'
# 配置
REDIS_HOST = '192.168.101.118'
REDIS_PORT = 6379
REDIS_DB = 0
DEFAULT_TIMEOUT = (60*20)
GPU_SERVER_TIME_OUT = 180
GPU_SERVER_LIST = 'gpu_server_list_key'
SERVER_LOG_ = "server_log"
SERVER_LOG_EVENT_LEN = 30
KEY_QUEUE_LOCK_NAME = 'KEY_QUEUE_LOCK_NAME'
SERVER_LIST_LOCK_NAME = 'SERVER_LIST_LOCK_NAME'
SERVER_LIST_LOG_LOCK_NAME = 'SERVER_LIST_LOG_LOCK_NAME'


# 创建 logger
logger = logging.getLogger(__name__)
logger.setLevel(logging.INFO)  # 设置 logger 的级别

# 创建文件 handler
file_handler = logging.FileHandler('/var/log/fuyan/config.log')
file_handler.setLevel(logging.INFO)
file_formatter = logging.Formatter('%(asctime)s - %(levelname)s - %(message)s')
file_handler.setFormatter(file_formatter)

# 创建控制台 handler
console_handler = logging.StreamHandler()
console_handler.setLevel(logging.INFO)
console_formatter = logging.Formatter('%(asctime)s - %(levelname)s - %(message)s')
console_handler.setFormatter(console_formatter)

# 添加 handlers 到 logger
logger.addHandler(file_handler)
logger.addHandler(console_handler)

selfComputer = "5090"

if selfComputer == "5090":
    change_tuodi_input = 'change_tuodi_input_api.json'
    change_only_name = "change_new_only_change.json"
    change_with_add_cloth = "change_new_debug_api.json"
    xiezhen_name = "xiezhen-0812-40s_api.json"
    base64_test_port = 28888
else:
    change_tuodi_input = 'change_tuodi_input_3090_api.json'
    change_only_name = "change_new_only_3090.json"
    change_with_add_cloth = "change_new_3090_api.json"
    xiezhen_name = "xiezhen-0812-40s_api.json"
    base64_test_port = 18888



def acquire_lock(redis_client, lock_name):
    lock = Lock(
        redis_client,
        name=lock_name,
        timeout=30,
        blocking_timeout=10
    )
    acquired = lock.acquire()
    if acquired:
        return lock
    return None

