Skip to content

Commit

Permalink
make intervalSeconds and maxWorkers configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
berthubert committed Apr 13, 2024
1 parent 57622a1 commit a5578cb
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 6 deletions.
14 changes: 13 additions & 1 deletion luabridge.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down Expand Up @@ -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"});
Expand Down
9 changes: 4 additions & 5 deletions simplomon.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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++;
}
}
Expand Down
2 changes: 2 additions & 0 deletions simplomon.hh
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,8 @@ private:
extern std::vector<std::unique_ptr<Checker>> g_checkers;
extern std::unique_ptr<SQLiteWriter> g_sqlw;
extern std::optional<bool> g_haveIPv6;
extern int g_intervalSeconds;
extern int g_maxWorkers;

void checkLuaTable(sol::table data,
const std::set<std::string>& mandatory,
Expand Down

0 comments on commit a5578cb

Please sign in to comment.