-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmain.py
More file actions
67 lines (57 loc) · 1.95 KB
/
main.py
File metadata and controls
67 lines (57 loc) · 1.95 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
import logging
import os
import signal
import sys
import threading
import time
from scl.queue.taskQueue import TaskQueue
from scl.queue.capTaskQueues import CapabilityTaskQueues
from scl.queue.awaitingApproveQueue import AwaitingApproveQueue
from scl.queue.awaitingCapTasksQueue import AwaitingCapTasksQueue
from scl.listener.restful_watch import RestFulHandler
from scl.listener.file_watch import FileHandler
from scl.processor.task_processor import TaskProcessor
# 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")
# Ensure watch directory exists
watch_dir = os.getenv("TODO_WATCH_DIR", "./todo_folder")
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="0.0.0.0", port="8080")
file_observer = file_handler.start()
api_thread = threading.Thread(target=rest_handler.start, daemon=True)
# Wait for termination signal
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()
# Keep main thread alive
try:
while True:
time.sleep(1)
except KeyboardInterrupt:
shutdown(None, None)
if __name__ == "__main__":
main()