From a5578cbda6f531dc6a0400e72cfb968115efb8a2 Mon Sep 17 00:00:00 2001 From: bert hubert Date: Sat, 13 Apr 2024 22:02:35 +0200 Subject: [PATCH] make intervalSeconds and maxWorkers configurable --- luabridge.cc | 14 +++++++++++++- simplomon.cc | 9 ++++----- simplomon.hh | 2 ++ 3 files changed, 19 insertions(+), 6 deletions(-) diff --git a/luabridge.cc b/luabridge.cc index f651971..2514f77 100644 --- a/luabridge.cc +++ b/luabridge.cc @@ -5,7 +5,8 @@ using namespace std; sol::state g_lua; - +int g_intervalSeconds=60; +int g_maxWorkers = 16; /* every checker has a table of properties, and you get an error if you put unexpected things in there. DailyChime{utcHour=11} @@ -159,6 +160,17 @@ void initLua() g_notifiers.push_back(n); }); + + g_lua.set_function("intervalSeconds", [&](int seconds) { + g_intervalSeconds = seconds; + }); + + g_lua.set_function("maxWorkers", [&](int workers) { + if(workers <= 0) + throw std::runtime_error("maxWorkers must be a positive number"); + g_maxWorkers = workers; + }); + g_lua.set_function("Logger", [&](sol::table data) { checkLuaTable(data, {"filename"}); diff --git a/simplomon.cc b/simplomon.cc index 499f583..4756fe7 100644 --- a/simplomon.cc +++ b/simplomon.cc @@ -243,16 +243,15 @@ try updateWebService(); time_t passed = time(nullptr) - startRun; - int interval = 60; - if(passed < interval) { - int sleeptime = interval - passed; + if(passed < g_intervalSeconds) { + int sleeptime = g_intervalSeconds - passed; fmt::print(", sleeping {} seconds\n", sleeptime); sleep(sleeptime); } else { fmt::print(", did not meet our interval of {} seconds with {} workers, possibly raising\n", - interval, numWorkers); - if(numWorkers < 16) + g_intervalSeconds, numWorkers); + if(numWorkers < g_maxWorkers) numWorkers++; } } diff --git a/simplomon.hh b/simplomon.hh index ab40bbe..45cbcf2 100644 --- a/simplomon.hh +++ b/simplomon.hh @@ -339,6 +339,8 @@ private: extern std::vector> g_checkers; extern std::unique_ptr g_sqlw; extern std::optional g_haveIPv6; +extern int g_intervalSeconds; +extern int g_maxWorkers; void checkLuaTable(sol::table data, const std::set& mandatory,