#ifndef REGULAR_TASK_EXECUTION_CPP #define REGULAR_TASK_EXECUTION_CPP #include #include #include #include "utilities.cpp" using namespace std::chrono_literals; /* * RegularTaskExecution manager */ namespace RegularTaskExecution { /* * clears expired login lockouts */ void purgeExpiredLoginLockouts(pqxx::connection &connection) { Database::executeStatement_STATEMENT_PURGE_EXPIRED_LOGIN_LOCKOUTS(connection); } /* * clears expired Freelancer Reset Keys */ void purgeExpiredFreelancerResetKeys(pqxx::connection &connection) { Database::executeStatement_STATEMENT_PURGE_EXPIRED_FREELANCER_RESET_KEYS(connection); } void regularExecution(const Utilities::config& configuration) { std::chrono::seconds seconds(configuration.regularTaskExecutionIntervalSeconds); pqxx::connection databaseConnection(configuration.databaseConnectionString); size_t counter = 0; std::cout << "REGULAR EXECUTION START: " << std::endl; while (configuration.regularTaskExecution) { std::cout << "REGULAR EXECUTION LOOP: " << counter << std::endl; if (configuration.regularTaskExecutionModules.at(Utilities::MODULE_NAME_BRUTE_FORCE_MITIGATION_CLEANER)) purgeExpiredLoginLockouts(databaseConnection); if (configuration.regularTaskExecutionModules.at(Utilities::MODULE_NAME_FREELANCER_RESET_KEY_CLEANER)) purgeExpiredFreelancerResetKeys(databaseConnection); counter++; std::this_thread::sleep_for(seconds); } } } #endif