BareGit

Run the scheduler from main

Start monitoring alongside the HTTP server and coordinate shutdown through a stop token.
Stop the server when scheduler execution reports an error.
Author: MetroWind <chris.corsair@gmail.com>
Date: Sat Sep 19 11:16:49 2026 -0700
Commit: c5c2a7f5cc22ceab18538a550a078d49e2bff85a

Changes

diff --git a/src/main.cpp b/src/main.cpp
index d5e5965..b51004d 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -1,10 +1,12 @@
 #include <filesystem>
 #include <iostream>
 #include <string_view>
+#include <thread>
 #include <utility>
 
 #include "app.h"
 #include "data_source_sqlite.h"
+#include "scheduler.h"
 
 namespace
 {
@@ -42,6 +44,12 @@ int main(int argc, char** argv)
         std::cerr << data_source.error().msg() << '\n';
         return 1;
     }
+    auto scheduler = Scheduler::create(*configuration, **data_source);
+    if(!scheduler)
+    {
+        std::cerr << scheduler.error().msg() << '\n';
+        return 1;
+    }
     App app(mw::IPSocketInfo{"127.0.0.1", 8080},
             std::move(*configuration), **data_source);
     auto started = app.start();
@@ -50,8 +58,19 @@ int main(int argc, char** argv)
         std::cerr << started.error().msg() << '\n';
         return 1;
     }
+    std::jthread scheduler_thread(
+        [scheduler = std::move(*scheduler), &app](std::stop_token stop) {
+            auto result = scheduler->run(stop);
+            if(!result)
+            {
+                std::cerr << "Scheduler stopped: "
+                          << result.error().msg() << '\n';
+                app.stop();
+            }
+        });
     std::cout << "Status Tracker listening on http://127.0.0.1:8080\n"
               << std::flush;
     app.wait();
+    scheduler_thread.request_stop();
     return 0;
 }