您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

1 个月前
12345678910111213141516171819202122232425262728
  1. from app.celery_app import celery
  2. from fastapi import Request,FastAPI
  3. import time
  4. @celery.task(name='app.tasks.add_task', bind=True, acks_late=True)
  5. def add_task(self, x, y):
  6. time.sleep(5) # 模拟长时间计算
  7. return x + y
  8. @celery.task(name='app.tasks.mul_task', bind=True, acks_late=True)
  9. def mul_task(self, x, y):
  10. time.sleep(5) # 模拟长时间计算
  11. return x * y
  12. # @celery.task(name='app.tasks.sync_contacts', bind=True, acks_late=True)
  13. # async def sync_contacts_task(self,app):
  14. # login_keys = list(await app.state.redis_service.client.scan_iter(match='__AI_OPS_WX__:LOGININFO:*'))
  15. # return login_keys
  16. # # for k in login_keys:
  17. # # print(k)
  18. @celery.task(name='app.tasks.sync_contacts', bind=True, acks_late=True)
  19. async def sync_contacts_task(self, redis_service):
  20. # Use the redis_service passed as an argument
  21. login_keys = list(await redis_service.client.scan_iter(match='__AI_OPS_WX__:LOGININFO:*'))
  22. return login_keys