|
@@ -16,7 +16,7 @@ from applications.feishu import bot
|
|
|
from applications.config.const import HistoryContentIdTaskConst
|
|
|
|
|
|
|
|
|
-async def main(publish_flag):
|
|
|
+async def do_job(publish_flag):
|
|
|
"""
|
|
|
main job
|
|
|
:return:
|
|
@@ -72,7 +72,7 @@ def run_thread(publish_flag, sleep_seconds, stop_flag):
|
|
|
while not stop_flag.is_set():
|
|
|
loop = asyncio.new_event_loop()
|
|
|
asyncio.set_event_loop(loop)
|
|
|
- loop.run_until_complete(main(publish_flag=publish_flag))
|
|
|
+ loop.run_until_complete(do_job(publish_flag=publish_flag))
|
|
|
loop.close()
|
|
|
now_str = datetime.datetime.now().__str__()
|
|
|
logging(
|
|
@@ -84,20 +84,26 @@ def run_thread(publish_flag, sleep_seconds, stop_flag):
|
|
|
time.sleep(sleep_seconds)
|
|
|
|
|
|
|
|
|
-if __name__ == '__main__':
|
|
|
+def main():
|
|
|
+ """
|
|
|
+ main function
|
|
|
+ """
|
|
|
const = HistoryContentIdTaskConst()
|
|
|
-
|
|
|
stop_event = threading.Event()
|
|
|
+
|
|
|
# 启动两个线程,分别执行两个函数
|
|
|
with ThreadPoolExecutor(max_workers=2) as executor:
|
|
|
futures = [
|
|
|
executor.submit(run_thread, const.NEED_PUBLISH, const.NEED_PUBLISH_WAIT_TIME, stop_event),
|
|
|
executor.submit(run_thread, const.DO_NOT_NEED_PUBLISH, const.DO_NOT_NEED_PUBLISH_WAIT_TIME, stop_event)
|
|
|
]
|
|
|
-
|
|
|
try:
|
|
|
for future in as_completed(futures):
|
|
|
future.result()
|
|
|
except KeyboardInterrupt:
|
|
|
print("Stopping all threads...")
|
|
|
- stop_event.set()
|
|
|
+ stop_event.set()
|
|
|
+
|
|
|
+
|
|
|
+if __name__ == '__main__':
|
|
|
+ main()
|