31 lines
928 B
Python
31 lines
928 B
Python
#!/usr/bin/env python3
|
||
"""
|
||
Queue configuration using SqliteHuey for asynchronous file processing.
|
||
"""
|
||
|
||
import os
|
||
import logging
|
||
from huey import SqliteHuey
|
||
from datetime import timedelta
|
||
|
||
# 配置日志
|
||
logger = logging.getLogger('app')
|
||
|
||
# 确保projects/queue_data目录存在
|
||
queue_data_dir = os.path.join(os.path.dirname(__file__), '..', 'projects', 'queue_data')
|
||
os.makedirs(queue_data_dir, exist_ok=True)
|
||
|
||
# 初始化SqliteHuey
|
||
huey = SqliteHuey(
|
||
filename=os.path.join(queue_data_dir, 'huey.db'),
|
||
name='file_processor', # 队列名称
|
||
always_eager=False, # 设置为False以启用异步处理
|
||
utc=True, # 使用UTC时间
|
||
)
|
||
|
||
# 设置默认任务配置
|
||
huey.store_errors = True # 存储错误信息
|
||
huey.max_retries = 3 # 最大重试次数
|
||
huey.retry_delay = timedelta(seconds=60) # 重试延迟
|
||
|
||
logger.info(f"SqliteHuey队列已初始化,数据库路径: {os.path.join(queue_data_dir, 'huey.db')}") |