Files
kami_apple_exchage/backend/test_arq_detailed.py
danial 8ad2a5366a refactor(backend): 将Celery替换为Arq进行协程任务处理
本次提交将后端的任务队列系统从Celery迁移到了Arq,以支持基于协程的任务处理。主要改动包括:
- 更新文档和配置文件,反映架构变化。
- 修改健康检查和服务初始化逻辑,以适应Arq的使用。
- 移除与Celery相关的代码,并添加Arq任务定义和调度器。
- 更新Dockerfile和相关脚本,确保Arq worker能够正确运行。
- 调整API和业务服务中的任务处理逻辑,移除对Celery的依赖。

这些改动旨在提高系统的异步处理能力和整体性能。
2025-09-18 16:02:05 +08:00

63 lines
2.1 KiB
Python

#!/usr/bin/env python3
"""Detailed test script to check arq context API"""
import asyncio
from arq.worker import Worker
from arq.connections import RedisSettings
async def detailed_task(ctx):
"""Detailed task to check context attributes"""
print("=== CONTEXT DETAILED INSPECTION ===")
print(f"Context type: {type(ctx)}")
# Get all attributes
attributes = [attr for attr in dir(ctx) if not attr.startswith('_')]
print(f"Public attributes: {attributes}")
# Check specific important attributes
important_attrs = ['job_id', 'retry', 'redis', 'job_try', 'enqueue_time']
for attr in important_attrs:
if hasattr(ctx, attr):
value = getattr(ctx, attr)
print(f"{attr}: {value} (type: {type(value)})")
if callable(value):
print(f" {attr} is callable")
else:
print(f"{attr}: NOT FOUND")
# Test retry functionality if it exists
if hasattr(ctx, 'retry') and callable(ctx.retry):
try:
# Just check if we can call it, but don't actually retry
retry_info = ctx.retry.__doc__ or "No docstring"
print(f"retry doc: {retry_info[:100]}...")
except Exception as e:
print(f"retry check error: {e}")
return {"success": True, "detailed_inspection": True}
async def main():
print("Running detailed arq context inspection...")
# Create worker with our test task
worker = Worker(
functions=[detailed_task],
redis_settings=RedisSettings(host='localhost'),
max_jobs=1
)
print("Worker setup complete")
print("Note: To see actual context attributes, this would need to run in a real arq worker process")
print("This test confirms basic arq functionality works")
# Check if we can access the retry mechanism through imports
try:
from arq.jobs import Job
print("Job class available")
except ImportError as e:
print(f"Job import error: {e}")
print("\nBasic arq setup is working correctly")
if __name__ == "__main__":
asyncio.run(main())