From 4df453867abca0026f2e51f1cf7d927542c5c11c Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sun, 5 Jul 2026 18:59:48 +0100 Subject: Add option --job Allows running with retry-uninsertable or purge-old-logs from the command line. --- src/webstat_logger_main.cpp | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/src/webstat_logger_main.cpp b/src/webstat_logger_main.cpp index 963e318..509f139 100644 --- a/src/webstat_logger_main.cpp +++ b/src/webstat_logger_main.cpp @@ -1,6 +1,7 @@ #include "ingestor.hpp" #include "util.hpp" #include +#include #include #include #include @@ -31,6 +32,23 @@ namespace { va_end(args); } }; + + int + runJobByName(WebStat::Ingestor & ingestor, const std::string_view jobName) + { + const std::flat_map jobs { + {"retry-uninsertable", &WebStat::Ingestor::jobRetryUninsertableLines}, + {"purge-old-logs", &WebStat::Ingestor::jobPurgeOldLogs}, + }; + if (const auto job = jobs.find(jobName); job != jobs.end()) { + std::println(std::cout, "Running job {}...", jobName); + const auto result = (ingestor.*(job->second))()(); + std::println(std::cout, "Result: {}", result); + return EXIT_SUCCESS; + } + std::println(std::cerr, "Job {} does not exist", jobName); + return EXIT_FAILURE; + } } #define LEXICAL_CAST_DURATION(UNIT) \ @@ -58,6 +76,7 @@ main(int argc, char ** argv) // clang-format off opts.add_options() ("help,h", "Show this help message") + ("job", po::value(), "Run only this job once and exit") ("config,c", po::value(), "Read config from this config file") ("db.type", po::value(&settings.dbType)->default_value(settings.dbType), "Database connection type") @@ -101,7 +120,13 @@ main(int argc, char ** argv) po::notify(optVars); try { - MainIngestor {getHostDetail(), std::move(settings)}.ingestLog(stdin); + MainIngestor ingestor {getHostDetail(), std::move(settings)}; + + if (const auto jobNameItr = optVars.find("job"); jobNameItr != optVars.end()) { + return runJobByName(ingestor, jobNameItr->second.as()); + } + + ingestor.ingestLog(stdin); return EXIT_SUCCESS; } catch (const std::exception & excp) { -- cgit v1.3