auto_rechunk_task.py 875 B

1234567891011121314151617181920212223242526272829
  1. from applications.utils.http import AsyncHttpClient
  2. class AutoRechunkTask:
  3. def __init__(self, mysql_client):
  4. self.mysql_client = mysql_client
  5. async def get_tasks(self):
  6. query = """
  7. SELECT doc_id, title, text, text_type, dataset_id
  8. FROM contents
  9. WHERE status = %s;
  10. """
  11. tasks = await self.mysql_client.async_fetch(query, params=(0,))
  12. return tasks
  13. @staticmethod
  14. async def rechunk(task):
  15. url = "http://192.168.100.31:8001/api/chunk"
  16. async with AsyncHttpClient() as http_client:
  17. response = await http_client.post(url, json=task, headers={"Content-Type": "application/json"})
  18. return response
  19. async def deal(self):
  20. tasks = await self.get_tasks()
  21. for task in tasks:
  22. await self.rechunk(task)
  23. return len(tasks)