forked from pschlan/cron-job.org
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.h
105 lines (91 loc) · 2.69 KB
/
App.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
/*
* chronos, the cron-job.org execution daemon
* Copyright (C) 2017 Patrick Schlangen <[email protected]>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
*/
#ifndef _APP_H_
#define _APP_H_
#include <memory>
#include <thread>
#include <vector>
#include <time.h>
#include "MySQL.h"
#include "Config.h"
#include "Utils.h"
class UserGroup;
namespace Chronos
{
class MySQL_DB;
class UpdateThread;
class NotificationThread;
class WorkerThread;
class NodeService;
class TestRunThread;
class MasterService;
class HTTPRequest;
class App
{
struct Private;
public:
App(int argc, char *argv[]);
~App();
private:
App(const App &other) = delete;
App(App &&other) = delete;
App &operator=(const App &other) = delete;
App &operator=(App &&other) = delete;
public:
static App *getInstance();
static void signalHandler(int sig);
void updateThreadMain();
void notificationThreadMain();
void nodeServiceThreadMain();
void testRunThreadMain();
void masterServiceThreadMain();
int run();
std::unique_ptr<MySQL_DB> createMySQLConnection();
std::unique_ptr<MySQL_DB> createMasterMySQLConnection();
UserGroup getUserGroupById(uint64_t userGroupId);
private:
void startUpdateThread();
void stopUpdateThread();
void startNotificationThread();
void stopNotificationThread();
void startNodeServiceThread();
void stopNodeServiceThread();
void startTestRunThread();
void stopTestRunThread();
void startMasterServiceThread();
void stopMasterServiceThread();
void processJobs(time_t forTime, time_t plannedTime);
void processJobsForTimeZone(int hour, int minute, int month, int mday, int wday, int year, time_t timestamp, const std::string &timeZone,
std::map<uint8_t, std::vector<HTTPRequest *>> &requestsByPriority);
void cleanUpNotifications();
void syncUserGroups();
public:
std::shared_ptr<Config> config;
bool isIpAddressBlocked(in_addr_t ipAddress) const;
private:
bool stop = false;
static App *instance;
std::unique_ptr<Private> priv;
std::thread updateThread;
std::thread notificationThread;
std::thread nodeServiceThread;
std::thread testRunThread;
std::thread masterServiceThread;
std::unique_ptr<MySQL_DB> db;
std::unique_ptr<UpdateThread> updateThreadObj;
std::unique_ptr<NotificationThread> notificationThreadObj;
std::unique_ptr<NodeService> nodeServiceObj;
std::unique_ptr<TestRunThread> testRunThreadObj;
std::unique_ptr<MasterService> masterServiceObj;
std::vector<Utils::Subnet> blockedSubnets;
};
};
#endif