mirror of
https://github.com/hoytech/strfry.git
synced 2025-06-19 09:36:43 +00:00
refactor cron
This commit is contained in:
@ -1,9 +1,21 @@
|
||||
#include <hoytech/timer.h>
|
||||
|
||||
#include "RelayServer.h"
|
||||
|
||||
#include "gc.h"
|
||||
|
||||
|
||||
void RelayServer::cleanupOldEvents() {
|
||||
void RelayServer::runCron() {
|
||||
auto qdb = getQdbInstance();
|
||||
|
||||
hoytech::timer cron;
|
||||
|
||||
cron.setupCb = []{ setThreadName("cron"); };
|
||||
|
||||
|
||||
// Delete ephemeral events
|
||||
|
||||
cron.repeat(10 * 1'000'000UL, [&]{
|
||||
std::vector<uint64_t> expiredLevIds;
|
||||
|
||||
{
|
||||
@ -42,8 +54,6 @@ void RelayServer::cleanupOldEvents() {
|
||||
}
|
||||
|
||||
if (expiredLevIds.size() > 0) {
|
||||
auto qdb = getQdbInstance();
|
||||
|
||||
auto txn = env.txn_rw();
|
||||
|
||||
uint64_t numDeleted = 0;
|
||||
@ -62,10 +72,15 @@ void RelayServer::cleanupOldEvents() {
|
||||
|
||||
if (numDeleted) LI << "Deleted " << numDeleted << " ephemeral events";
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
void RelayServer::garbageCollect() {
|
||||
auto qdb = getQdbInstance();
|
||||
// Garbage collect quadrable nodes
|
||||
|
||||
cron.repeat(60 * 60 * 1'000'000UL, [&]{
|
||||
quadrableGarbageCollect(qdb, 1);
|
||||
});
|
||||
|
||||
cron.run();
|
||||
|
||||
while (1) std::this_thread::sleep_for(std::chrono::seconds(1'000'000));
|
||||
}
|
||||
|
@ -4,7 +4,6 @@
|
||||
#include <memory>
|
||||
#include <algorithm>
|
||||
|
||||
#include <hoytech/timer.h>
|
||||
#include <hoytech/time.h>
|
||||
#include <hoytech/hex.h>
|
||||
#include <hoytech/file_change_monitor.h>
|
||||
@ -142,7 +141,7 @@ struct RelayServer {
|
||||
ThreadPool<MsgReqWorker> tpReqWorker;
|
||||
ThreadPool<MsgReqMonitor> tpReqMonitor;
|
||||
ThreadPool<MsgYesstr> tpYesstr;
|
||||
hoytech::timer cron;
|
||||
std::thread cronThread;
|
||||
|
||||
void run();
|
||||
|
||||
@ -161,8 +160,7 @@ struct RelayServer {
|
||||
|
||||
void runYesstr(ThreadPool<MsgYesstr>::Thread &thr);
|
||||
|
||||
void cleanupOldEvents();
|
||||
void garbageCollect();
|
||||
void runCron();
|
||||
|
||||
// Utils (can be called by any thread)
|
||||
|
||||
|
@ -32,6 +32,10 @@ void RelayServer::run() {
|
||||
runYesstr(thr);
|
||||
});
|
||||
|
||||
cronThread = std::thread([this]{
|
||||
runCron();
|
||||
});
|
||||
|
||||
// Monitor for config file reloads
|
||||
|
||||
auto configFileChangeWatcher = hoytech::file_change_monitor(configFile);
|
||||
@ -42,19 +46,6 @@ void RelayServer::run() {
|
||||
loadConfig(configFile);
|
||||
});
|
||||
|
||||
// Cron
|
||||
|
||||
cron.repeat(10 * 1'000'000UL, [&]{
|
||||
cleanupOldEvents();
|
||||
});
|
||||
|
||||
cron.repeat(60 * 60 * 1'000'000UL, [&]{
|
||||
garbageCollect();
|
||||
});
|
||||
|
||||
cron.setupCb = []{ setThreadName("cron"); };
|
||||
|
||||
cron.run();
|
||||
|
||||
tpWebsocket.join();
|
||||
}
|
||||
|
Reference in New Issue
Block a user