historyTask.py 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. """
  2. @author: luojunhui
  3. """
  4. import time
  5. import asyncio
  6. import datetime
  7. import traceback
  8. from tasks.history_task import historyContentIdTask
  9. from applications.db import AsyncMySQLClient
  10. from applications.log import logging
  11. from applications.feishu import bot
  12. async def main():
  13. """
  14. main job
  15. :return:
  16. """
  17. async_mysql_pool = AsyncMySQLClient()
  18. try:
  19. await async_mysql_pool.init_pool()
  20. logging(
  21. code="history0001",
  22. info="Init MySQL pool successfully",
  23. alg="historyContentIdTask",
  24. function="main"
  25. )
  26. except Exception as e:
  27. logging(
  28. code="history0002",
  29. info="Init MySQL pool failed",
  30. alg="historyContentIdTask",
  31. function="main",
  32. data={
  33. "error": str(e),
  34. "traceback": traceback.format_exc()
  35. }
  36. )
  37. bot(
  38. title="historyContentIdTask INIT MYSQL FAILS",
  39. detail={
  40. "error": str(e),
  41. "traceback": traceback.format_exc()
  42. }
  43. )
  44. try:
  45. history_content_id_task = historyContentIdTask(async_mysql_pool)
  46. except Exception as e:
  47. logging(
  48. code="history0003",
  49. info="Init historyContentIdTask failed",
  50. alg="historyContentIdTask",
  51. function="main",
  52. data={
  53. "error": str(e),
  54. "traceback": traceback.format_exc()
  55. }
  56. )
  57. return
  58. await history_content_id_task.deal()
  59. if __name__ == '__main__':
  60. while True:
  61. asyncio.run(main())
  62. now_str = datetime.datetime.now().__str__()
  63. print("{} 请求执行完成, 等待60s".format(now_str))
  64. logging(
  65. code="history0004",
  66. info="History task finished"
  67. )
  68. time.sleep(60)