Skip to content

Commit

Permalink
feat: worker thread to process workflow queue
Browse files Browse the repository at this point in the history
  • Loading branch information
samcole8 committed Feb 25, 2025
1 parent f7333f2 commit 7bad9bc
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions sendlog/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,16 @@
from utils.workflow_manager import WorkflowManager
from log_monitor import LogMonitor

import threading
import queue
import time

def process_workflows(workflow_queue):
while True:
workflow, msg = workflow_queue.get()
workflow.execute(msg)
workflow_queue.task_done()

def main():
# Load config into ConfigHandler
config_handler = ConfigHandler("sendlog.yml")
Expand All @@ -16,13 +26,19 @@ def main():
# Load file workflows from config
for data in config_handler.files():
workflow_manager.load_workflow(*data)


# Set up worker thread
workflow_queue = queue.Queue()
worker_thread = threading.Thread(target=process_workflows, args=(workflow_queue,))
worker_thread.daemon = True
worker_thread.start()

# Start file monitoring
paths = workflow_manager.get_paths()
log_monitor = LogMonitor(paths)
for path, msg in log_monitor.monitor():
print(f"{path}: {msg}")
# workflow_manager.get_workflow(path).execute(msg)
workflow = workflow_manager.get_workflow(path)
workflow_queue.put((workflow, msg))


if __name__ == "__main__":
Expand Down

0 comments on commit 7bad9bc

Please sign in to comment.