Files
kami_apple_exchage/backend/test_worker_simple.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

43 lines
1.1 KiB
Python

#!/usr/bin/env python3
"""Simple test to understand arq worker usage"""
import asyncio
from arq.worker import Worker
from arq.connections import RedisSettings
def simple_task(ctx):
"""Simple test task"""
print(f"Task executed with job_id: {ctx.job_id}")
return {"success": True}
async def test_worker():
"""Test creating and running a worker"""
print("Testing arq worker creation...")
# Try creating a worker
worker = Worker(
functions=[simple_task],
redis_settings=RedisSettings(host='localhost'),
max_jobs=5
)
print("Worker created successfully")
print("Worker type:", type(worker))
# Check if worker has run method
if hasattr(worker, 'run'):
print("Worker has 'run' method")
sig = str(type(worker.run))
print("run method type:", sig)
if hasattr(worker, 'main'):
print("Worker has 'main' method")
if hasattr(worker, 'start'):
print("Worker has 'start' method")
return worker
if __name__ == "__main__":
asyncio.run(test_worker())