Added a run_at, run_every and run_on_start, making the app a daemon like entity.
This commit is contained in:
parent
111c2487d8
commit
41c405a0c5
1 changed files with 694 additions and 46 deletions
27
appinfo.h
27
appinfo.h
|
|
@ -8,6 +8,8 @@
|
|||
#include <unordered_map>
|
||||
#include <syncstream>
|
||||
#include <atomic>
|
||||
#include <format>
|
||||
#include <chrono>
|
||||
|
||||
class AppInfo
|
||||
{
|
||||
|
|
@ -32,6 +34,9 @@ public:
|
|||
std::string run_mode;
|
||||
std::string run_as;
|
||||
bool create_log = false;
|
||||
std::string run_at;
|
||||
std::string run_every;
|
||||
bool run_on_start = false;
|
||||
void printInfo(std::ostream &out);
|
||||
std::string getAfterString() const;
|
||||
std::string getAfterKeys() const;
|
||||
|
|
@ -43,12 +48,19 @@ private:
|
|||
std::deque<std::string> args;
|
||||
std::string run_as;
|
||||
std::string working_dir;
|
||||
std::string run_at;
|
||||
std::string run_every;
|
||||
bool run_on_start = false;
|
||||
string_map after;
|
||||
string_map env;
|
||||
bool create_log = false;
|
||||
std::unordered_map<std::shared_ptr<AppInfo>, State> parents;
|
||||
std::atomic<State> state{State::initial};
|
||||
RunMode mode = RunMode::script;
|
||||
std::chrono::system_clock::time_point next_time_to_run;
|
||||
bool next_time_to_run_parse_failed = false;
|
||||
bool scheduled = false;
|
||||
std::vector<pid_t> previous_execution_list;
|
||||
public:
|
||||
void setProgramName(std::string name);
|
||||
void setModuleName(std::string name);
|
||||
|
|
@ -59,8 +71,10 @@ public:
|
|||
void setCreateLog(bool create_log);
|
||||
void setRunMode(std::string mode);
|
||||
void setRunAs(std::string run_as);
|
||||
void setScheduled(bool val);
|
||||
void setFinished();
|
||||
void setRunning();
|
||||
void addToPreviousExecutionList(pid_t new_process);
|
||||
void insertParent(std::shared_ptr<AppInfo> parent, State state);
|
||||
bool isParentDependencyCleared(std::osyncstream &out) const;
|
||||
std::string getModuleName() const;
|
||||
|
|
@ -73,10 +87,15 @@ public:
|
|||
std::string getAfterString() const;
|
||||
std::string getAfterKeys() const;
|
||||
RunMode getRunMode() const;
|
||||
std::string getStringRunMode() const;
|
||||
State getState() const;
|
||||
std::unordered_map<std::shared_ptr<AppInfo>, State> getParents() const;
|
||||
void copyFromData(AppInfo::AppData &other);
|
||||
bool getCreateLog();
|
||||
bool getScheduled();
|
||||
bool getRunOnStart();
|
||||
std::vector<pid_t> getPreviousExecutionList() const;
|
||||
std::chrono::system_clock::time_point getNextTimeToRun() const;
|
||||
AppInfo();
|
||||
~AppInfo();
|
||||
AppInfo(const AppInfo &other) = delete;
|
||||
|
|
@ -84,8 +103,16 @@ public:
|
|||
AppInfo &operator=(const AppInfo &other) = delete;
|
||||
bool operator==(const AppInfo &other);
|
||||
void printInfo(std::ostream& out);
|
||||
bool checkValidity();
|
||||
void updateNextTimeToRun();
|
||||
private:
|
||||
std::optional<std::chrono::system_clock::time_point> parseAtTimeFormat(std::string run_every);
|
||||
std::optional<std::chrono::system_clock::time_point> parseEveryTimeFormat(std::string run_every);
|
||||
std::string runmodeToString() const;
|
||||
std::vector<std::string> tokenize(std::string, std::string);
|
||||
std::string stringStrip(const std::string str);
|
||||
int integer(const std::string str);
|
||||
std::string tolower(const std::string str) const;
|
||||
std::string stateToString() const;
|
||||
std::string stateToString(State s) const;
|
||||
};
|
||||
|
|
|
|||
Loading…
Reference in a new issue