-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmain.py
More file actions
71 lines (56 loc) · 1.92 KB
/
Copy pathmain.py
File metadata and controls
71 lines (56 loc) · 1.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import logging
import os
import signal
import sys
import threading
import time
from scl.config import config
from scl.listener.file_watch import FileHandler
from scl.listener.restful_watch import RestFulHandler
from scl.processor.task_processor import TaskProcessor
from scl.queue.awaiting_approve_queue import AwaitingApproveQueue
from scl.queue.awaiting_cap_tasks_queue import AwaitingCapTasksQueue
from scl.queue.cap_task_queues import CapabilityTaskQueues
from scl.queue.task_queue import TaskQueue
# Setup telemetry
logger = logging.getLogger(__name__)
from scl.otel.otel import init_telemetry
init_telemetry()
def main():
todo_queue = TaskQueue()
captask_queue = CapabilityTaskQueues()
waiting_approval_queue = AwaitingApproveQueue()
waiting_captask_queue = AwaitingCapTasksQueue()
logger.info("Starting Todo Receiver Application")
# 从 config 读取监听目录
watch_dir = config.todo_watch_dir
os.makedirs(watch_dir, exist_ok=True)
# Start todo processor
processor = TaskProcessor(todo_queue)
processor.start()
# Start listeners
file_handler = FileHandler(
watch_path=watch_dir,
task_queue=todo_queue,
captask_queue=captask_queue,
waiting_approval_queue=waiting_approval_queue,
waiting_captask_queue=waiting_captask_queue,
)
rest_handler = RestFulHandler(watch_dir, host=config.api_host, port=config.api_port)
file_observer = file_handler.start()
api_thread = threading.Thread(target=rest_handler.start, daemon=True)
def shutdown(signum, frame):
logger.info("Shutting down...")
file_observer.stop()
file_observer.join()
sys.exit(0)
signal.signal(signal.SIGINT, shutdown)
signal.signal(signal.SIGTERM, shutdown)
api_thread.start()
try:
while True:
time.sleep(1)
except KeyboardInterrupt:
shutdown(None, None)
if __name__ == "__main__":
main()