new_history.py 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. """
  2. @author: luojunhui
  3. """
  4. import asyncio
  5. import time
  6. import traceback
  7. from tasks.new_history_task import NewHistoryTask
  8. from applications.db import AsyncMySQLClient
  9. from applications.log import logging
  10. from applications.feishu import bot
  11. async def main():
  12. """
  13. main job
  14. :return:
  15. """
  16. async_mysql_pool = AsyncMySQLClient()
  17. try:
  18. await async_mysql_pool.init_pool()
  19. logging(
  20. code="newHistory0001",
  21. info="Init MySQL pool successfully",
  22. alg="historyContentIdTask",
  23. function="main"
  24. )
  25. except Exception as e:
  26. logging(
  27. code="newHistory0002",
  28. info="Init MySQL pool failed",
  29. alg="historyContentIdTask",
  30. function="main",
  31. data={
  32. "error": str(e),
  33. "traceback": traceback.format_exc()
  34. }
  35. )
  36. bot(
  37. title="newHistoryContentIdTask INIT MYSQL FAILS",
  38. detail={
  39. "error": str(e),
  40. "traceback": traceback.format_exc()
  41. }
  42. )
  43. try:
  44. history_content_id_task = NewHistoryTask(async_mysql_pool)
  45. except Exception as e:
  46. logging(
  47. code="newHistory0003",
  48. info="Init newHistory0003 failed",
  49. alg="historyContentIdTask",
  50. function="main",
  51. data={
  52. "error": str(e),
  53. "traceback": traceback.format_exc()
  54. }
  55. )
  56. bot(
  57. title="newHistoryContentIdTask INIT TASK FAILS",
  58. detail={
  59. "error": str(e),
  60. "traceback": traceback.format_exc()
  61. }
  62. )
  63. return
  64. await history_content_id_task.deal_new()
  65. if __name__ == '__main__':
  66. while True:
  67. asyncio.run(main())
  68. time.sleep(5)