Regular Task Execution:

Added to spec
Added to config
Base implementation of 2 test modules
This commit is contained in:
Tina_Azure
2023-05-01 22:30:57 +02:00
parent 68a515dbda
commit a7e1fbb5f5
5 changed files with 99 additions and 7 deletions

View File

@ -249,6 +249,12 @@ mandatory:
optional:{default} optional:{default}
emailServerPort={587} emailServerPort={587}
emailAddressDisplay={Cavecomm Automated Management System} emailAddressDisplay={Cavecomm Automated Management System}
regularTaskExecution={false}
regularTaskExecutionIntervalSeconds={900} 15min
regularTaskExecutionModules={}
options separated by "|":
reeeprint: test module
counter: test module

View File

@ -12,6 +12,9 @@
# Optional: {default} # Optional: {default}
# emailServerPort={587} # emailServerPort={587}
# emailAddressDisplay={Cavecomm Automated Management System} # emailAddressDisplay={Cavecomm Automated Management System}
# regularTaskExecution={false}
# regularTaskExecutionIntervalSeconds={900} 15min
# regularTaskExecutionModules={} # options separated by "|": reeeprint|counter
@ -34,4 +37,10 @@ sslKeyPath=/media/sf_cavecommRemote/example.key;
domain=192.168.56.1:18080; domain=192.168.56.1:18080;
regularTaskExecution=true;
regularTaskExecutionIntervalSeconds=2;
regularTaskExecutionModules=reeeprint|counter;
#configend# #configend#

View File

@ -1,11 +1,15 @@
#include "crow.h"
#include "crow/middlewares/cookie_parser.h"
#include "database.cpp"
#include "utilities.cpp"
#include <pqxx/pqxx>
#include <vector> #include <vector>
#include <string> #include <string>
#include <fmt/core.h> #include <thread>
#include <pqxx/pqxx>
#include "crow.h"
#include "crow/middlewares/cookie_parser.h"
#include "database.cpp"
#include "utilities.cpp"
#include "regularTaskExecution.cpp"
using namespace std; using namespace std;
@ -23,6 +27,9 @@ int main(int argc, char *argv[]) {
// Create app with Middleware // Create app with Middleware
crow::App<crow::CookieParser> app; crow::App<crow::CookieParser> app;
// starts thread that executes modules
thread threadRegularExecution(RegularTaskExecution::regularExecution, configuration);
/* /*
* Freelancer Profile listing for customers * Freelancer Profile listing for customers
*/ */

View File

@ -0,0 +1,46 @@
#ifndef REGULAR_TASK_EXECUTION_CPP
#define REGULAR_TASK_EXECUTION_CPP
#include <iostream>
#include <chrono>
#include <thread>
#include "utilities.cpp"
using namespace std::chrono_literals;
/*
* RegularTaskExecution manager
*/
namespace RegularTaskExecution {
/*
* print test
* todo::remove
*/
void reeePrint() {
std::cout << "reeee" << std::endl;
}
/*
* print test
* todo::remove
*/
void counterPrint(size_t& counter) {
std::cout << counter << std::endl;
counter++;
}
void regularExecution(const Utilities::config& configuration) {
std::chrono::seconds seconds(configuration.regularTaskExecutionIntervalSeconds);
size_t counter = 0;
while (configuration.regularTaskExecution) {
if (configuration.regularTaskExecutionModules.at(Utilities::MODULE_NAME_REEE_PRINT))
reeePrint(); // print test todo::remove
if (configuration.regularTaskExecutionModules.at(Utilities::MODULE_NAME_REEE_PRINT))
counterPrint(counter); // print test todo::remove
std::this_thread::sleep_for(seconds);
}
}
}
#endif

View File

@ -22,7 +22,10 @@ using namespace DatabaseStatementConstCollection;
namespace Utilities { namespace Utilities {
const static std::map<std::string, std::string> HTML_URL_CODES = {{"%20", " "}, {"%21", "!"}, {"%22", "\""}, {"%23", "#"}, {"%24", "$"}, {"%25", "%"}, {"%26", "&"}, {"%27", "'"}, {"%28", "("}, {"%29", ")"}, {"%2A", "*"}, {"%2B", "+"}, {"%2C", ","}, {"%2D", "-"}, {"%2E", "."}, {"%2F", "/"}, {"%30", "0"}, {"%31", "1"}, {"%32", "2"}, {"%33", "3"}, {"%34", "4"}, {"%35", "5"}, {"%36", "6"}, {"%37", "7"}, {"%38", "8"}, {"%39", "9"}, {"%3A", ":"}, {"%3B", ";"}, {"%3C", "<"}, {"%3D", "="}, {"%3E", ">"}, {"%3F", "?"}, {"%40", "@"}, {"%5B", "["}, {"%5C", "\\"}, {"%5D", "]"}, {"%5E", "^"}, {"%5F", "_"}, {"%60", "`"}, {"%7B", "{"}, {"%7C", "|"}, {"%7D", "}"}, {"%7E", "~"}, {"%7F", " "}, {"%80", ""}, {"%82", ""}, {"%83", "ƒ"}, {"%84", ""}, {"%85", ""}, {"%86", ""}, {"%87", ""}, {"%88", "ˆ"}, {"%89", ""}, {"%8A", "Š"}, {"%8B", ""}, {"%8C", "Œ"}, {"%8E", "Ž"}, {"%91", ""}, {"%92", ""}, {"%93", ""}, {"%94", ""}, {"%95", ""}, {"%96", ""}, {"%97", ""}, {"%98", "˜"}, {"%99", ""}, {"%9A", "š"}, {"%9B", ""}, {"%9C", "œ"}, {"%9E", "ž"}, {"%9F", "Ÿ"}, {"%A1", "¡"}, {"%A2", "¢"}, {"%A3", "£"}, {"%A4", "¤"}, {"%A5", "¥"}, {"%A6", "¦"}, {"%A7", "§"}, {"%A8", "¨"}, {"%A9", "©"}, {"%AA", "ª"}, {"%AB", "«"}, {"%AC", "¬"}, {"%AE", "®"}, {"%AF", "¯"}, {"%B0", "°"}, {"%B1", "±"}, {"%B2", "²"}, {"%B3", "³"}, {"%B4", "´"}, {"%B5", "µ"}, {"%B6", ""}, {"%B7", "·"}, {"%B8", "¸"}, {"%B9", "¹"}, {"%BA", "º"}, {"%BB", "»"}, {"%BC", "¼"}, {"%BD", "½"}, {"%BE", "¾"}, {"%BF", "¿"}, {"%C0", "À"}, {"%C1", "Á"}, {"%C2", "Â"}, {"%C3", "Ã"}, {"%C4", "Ä"}, {"%C5", "Å"}, {"%C6", "Æ"}, {"%C7", "Ç"}, {"%C8", "È"}, {"%C9", "É"}, {"%CA", "Ê"}, {"%CB", "Ë"}, {"%CC", "Ì"}, {"%CD", "Í"}, {"%CE", "Î"}, {"%CF", "Ï"}, {"%D0", "Ð"}, {"%D1", "Ñ"}, {"%D2", "Ò"}, {"%D3", "Ó"}, {"%D4", "Ô"}, {"%D5", "Õ"}, {"%D6", "Ö"}, {"%D7", "×"}, {"%D8", "Ø"}, {"%D9", "Ù"}, {"%DA", "Ú"}, {"%DB", "Û"}, {"%DC", "Ü"}, {"%DD", "Ý"}, {"%DE", "Þ"}, {"%DF", "ß"}, {"%E0", "à"}, {"%E1", "á"}, {"%E2", "â"}, {"%E3", "ã"}, {"%E4", "ä"}, {"%E5", "å"}, {"%E6", "æ"}, {"%E7", "ç"}, {"%E8", "è"}, {"%E9", "é"}, {"%EA", "ê"}, {"%EB", "ë"}, {"%EC", "ì"}, {"%ED", "í"}, {"%EE", "î"}, {"%EF", "ï"}, {"%F0", "ð"}, {"%F1", "ñ"}, {"%F2", "ò"}, {"%F3", "ó"}, {"%F4", "ô"}, {"%F5", "õ"}, {"%F6", "ö"}, {"%F7", "÷"}, {"%F8", "ø"}, {"%F9", "ù"}, {"%FA", "ú"}, {"%FB", "û"}, {"%FC", "ü"}, {"%FD", "ý"}, {"%FE", "þ"}, {"%FF", "ÿ"}}; const static std::map<std::string, std::string> HTML_URL_CODES = {{"%20", " "}, {"%21", "!"}, {"%22", "\""}, {"%23", "#"}, {"%24", "$"}, {"%25", "%"}, {"%26", "&"}, {"%27", "'"}, {"%28", "("}, {"%29", ")"}, {"%2A", "*"}, {"%2B", "+"}, {"%2C", ","}, {"%2D", "-"}, {"%2E", "."}, {"%2F", "/"}, {"%30", "0"}, {"%31", "1"}, {"%32", "2"}, {"%33", "3"}, {"%34", "4"}, {"%35", "5"}, {"%36", "6"}, {"%37", "7"}, {"%38", "8"}, {"%39", "9"}, {"%3A", ":"}, {"%3B", ";"}, {"%3C", "<"}, {"%3D", "="}, {"%3E", ">"}, {"%3F", "?"}, {"%40", "@"}, {"%5B", "["}, {"%5C", "\\"}, {"%5D", "]"}, {"%5E", "^"}, {"%5F", "_"}, {"%60", "`"}, {"%7B", "{"}, {"%7C", "|"}, {"%7D", "}"}, {"%7E", "~"}, {"%7F", " "}, {"%80", ""}, {"%82", ""}, {"%83", "ƒ"}, {"%84", ""}, {"%85", ""}, {"%86", ""}, {"%87", ""}, {"%88", "ˆ"}, {"%89", ""}, {"%8A", "Š"}, {"%8B", ""}, {"%8C", "Œ"}, {"%8E", "Ž"}, {"%91", ""}, {"%92", ""}, {"%93", ""}, {"%94", ""}, {"%95", ""}, {"%96", ""}, {"%97", ""}, {"%98", "˜"}, {"%99", ""}, {"%9A", "š"}, {"%9B", ""}, {"%9C", "œ"}, {"%9E", "ž"}, {"%9F", "Ÿ"}, {"%A1", "¡"}, {"%A2", "¢"}, {"%A3", "£"}, {"%A4", "¤"}, {"%A5", "¥"}, {"%A6", "¦"}, {"%A7", "§"}, {"%A8", "¨"}, {"%A9", "©"}, {"%AA", "ª"}, {"%AB", "«"}, {"%AC", "¬"}, {"%AE", "®"}, {"%AF", "¯"}, {"%B0", "°"}, {"%B1", "±"}, {"%B2", "²"}, {"%B3", "³"}, {"%B4", "´"}, {"%B5", "µ"}, {"%B6", ""}, {"%B7", "·"}, {"%B8", "¸"}, {"%B9", "¹"}, {"%BA", "º"}, {"%BB", "»"}, {"%BC", "¼"}, {"%BD", "½"}, {"%BE", "¾"}, {"%BF", "¿"}, {"%C0", "À"}, {"%C1", "Á"}, {"%C2", "Â"}, {"%C3", "Ã"}, {"%C4", "Ä"}, {"%C5", "Å"}, {"%C6", "Æ"}, {"%C7", "Ç"}, {"%C8", "È"}, {"%C9", "É"}, {"%CA", "Ê"}, {"%CB", "Ë"}, {"%CC", "Ì"}, {"%CD", "Í"}, {"%CE", "Î"}, {"%CF", "Ï"}, {"%D0", "Ð"}, {"%D1", "Ñ"}, {"%D2", "Ò"}, {"%D3", "Ó"}, {"%D4", "Ô"}, {"%D5", "Õ"}, {"%D6", "Ö"}, {"%D7", "×"}, {"%D8", "Ø"}, {"%D9", "Ù"}, {"%DA", "Ú"}, {"%DB", "Û"}, {"%DC", "Ü"}, {"%DD", "Ý"}, {"%DE", "Þ"}, {"%DF", "ß"}, {"%E0", "à"}, {"%E1", "á"}, {"%E2", "â"}, {"%E3", "ã"}, {"%E4", "ä"}, {"%E5", "å"}, {"%E6", "æ"}, {"%E7", "ç"}, {"%E8", "è"}, {"%E9", "é"}, {"%EA", "ê"}, {"%EB", "ë"}, {"%EC", "ì"}, {"%ED", "í"}, {"%EE", "î"}, {"%EF", "ï"}, {"%F0", "ð"}, {"%F1", "ñ"}, {"%F2", "ò"}, {"%F3", "ó"}, {"%F4", "ô"}, {"%F5", "õ"}, {"%F6", "ö"}, {"%F7", "÷"}, {"%F8", "ø"}, {"%F9", "ù"}, {"%FA", "ú"}, {"%FB", "û"}, {"%FC", "ü"}, {"%FD", "ý"}, {"%FE", "þ"}, {"%FF", "ÿ"}};
const static int SALT_SIZE = 32; const static int SALT_SIZE = 32;
const std::string SALT_CHAR_SET = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; const static std::string SALT_CHAR_SET = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
const static std::string MODULE_NAME_REEE_PRINT = "reeeprint";
const static std::string MODULE_NAME_COUNTER_PRINT = "counter";
/* /*
* Takes string to split it into a vector based on a given delimiter * Takes string to split it into a vector based on a given delimiter
@ -59,6 +62,12 @@ namespace Utilities {
std::string sslCrtPath; std::string sslCrtPath;
std::string sslKeyPath; std::string sslKeyPath;
std::string domain; std::string domain;
bool regularTaskExecution = false;
int regularTaskExecutionIntervalSeconds = 900;
std::map<std::string, bool> regularTaskExecutionModules = {
{MODULE_NAME_REEE_PRINT, false},
{MODULE_NAME_COUNTER_PRINT, false}
};
/* /*
* validates existence of mandatory variables in config * validates existence of mandatory variables in config
@ -159,6 +168,21 @@ namespace Utilities {
domain = trimFromDelimiter(lineVector.at(1), ';'); domain = trimFromDelimiter(lineVector.at(1), ';');
continue; continue;
} }
if (lineVector.at(0) == "regularTaskExecution") {
regularTaskExecution = (trimFromDelimiter(lineVector.at(1), ';') == "true");
continue;
}
if (lineVector.at(0) == "regularTaskExecutionIntervalSeconds") {
regularTaskExecutionIntervalSeconds = std::stoi(trimFromDelimiter(lineVector.at(1), ';'));
continue;
}
if (lineVector.at(0) == "regularTaskExecutionModules") {
std::vector<std::string> modules = Utilities::splitStringIntoVector(trimFromDelimiter(lineVector.at(1), ';'), '|');
for (const std::string& module : modules) {
regularTaskExecutionModules.at(module) = true;
}
continue;
}
} }
} }
} }