2024-09-21 14:20:36 +00:00
|
|
|
// Announcements.
|
|
|
|
import "./Jobs/Announcement/SendNotificationToSubscribers";
|
|
|
|
// Hard Delete
|
|
|
|
import "./Jobs/HardDelete/HardDeleteItemsInDatabase";
|
|
|
|
// Incidents
|
|
|
|
import "./Jobs/Incident/SendNotificationToSubscribers";
|
|
|
|
// Incident Owners
|
|
|
|
import "./Jobs/IncidentOwners/SendCreatedResourceNotification";
|
|
|
|
import "./Jobs/IncidentOwners/SendNotePostedNotification";
|
|
|
|
import "./Jobs/IncidentOwners/SendOwnerAddedNotification";
|
|
|
|
import "./Jobs/IncidentOwners/SendStateChangeNotification";
|
|
|
|
// Incident Notes
|
|
|
|
import "./Jobs/IncidentPublicNote/SendNotificationToSubscribers";
|
|
|
|
import "./Jobs/IncidentStateTimeline/SendNotificationToSubscribers";
|
|
|
|
import "./Jobs/IncomingRequestMonitor/CheckHeartbeat";
|
|
|
|
import "./Jobs/MeteredPlan/ReportTelemetryMeteredPlan";
|
2024-09-21 15:17:32 +00:00
|
|
|
|
2024-09-21 14:47:55 +00:00
|
|
|
// Monitor Metrics
|
2024-09-22 10:14:30 +00:00
|
|
|
import "./Jobs/MonitorMetrics/MonitorMetricsByMinute";
|
2024-09-21 15:17:32 +00:00
|
|
|
|
2024-09-21 14:47:55 +00:00
|
|
|
// Monitor Owners
|
|
|
|
import "./Jobs/MonitorOwners/SendCreatedResourceNotification";
|
|
|
|
import "./Jobs/MonitorOwners/SendOwnerAddedNotification";
|
|
|
|
import "./Jobs/MonitorOwners/SendStatusChangeNotification";
|
|
|
|
// On-Call Duty Policy Executions.
|
|
|
|
import "./Jobs/OnCallDutyPolicyExecutionLog/ExecutePendingExecutions";
|
|
|
|
import "./Jobs/OnCallDutyPolicyExecutionLog/TimeoutStuckExecutions";
|
|
|
|
// Payments.
|
|
|
|
import "./Jobs/PaymentProvider/CheckSubscriptionStatus";
|
|
|
|
import "./Jobs/PaymentProvider/PopulatePlanNameInProject";
|
|
|
|
import "./Jobs/PaymentProvider/UpdateTeamMembersIfNull";
|
|
|
|
import "./Jobs/ScheduledMaintenance/ChangeStateToEnded";
|
2024-09-21 16:05:05 +00:00
|
|
|
|
2024-09-21 19:06:22 +00:00
|
|
|
// Scheduled Event
|
|
|
|
import "./Jobs/ScheduledMaintenance/ChangeStateToOngoing";
|
|
|
|
import "./Jobs/ScheduledMaintenance/SendNotificationToSubscribers";
|
|
|
|
import "./Jobs/ScheduledMaintenance/ScheduleRecurringEvents";
|
|
|
|
import "./Jobs/ScheduledMaintenance/SendSubscriberRemindersOnEventScheduled";
|
2024-09-21 14:03:16 +00:00
|
|
|
|
2024-09-21 15:01:50 +00:00
|
|
|
// Scheduled Event Owners
|
|
|
|
import "./Jobs/ScheduledMaintenanceOwners/SendCreatedResourceNotification";
|
|
|
|
import "./Jobs/ScheduledMaintenanceOwners/SendNotePostedNotification";
|
|
|
|
import "./Jobs/ScheduledMaintenanceOwners/SendOwnerAddedNotification";
|
|
|
|
import "./Jobs/ScheduledMaintenanceOwners/SendStateChangeNotification";
|
2024-09-21 14:03:16 +00:00
|
|
|
|
2024-09-21 15:01:50 +00:00
|
|
|
// Scheduled Event Notes
|
|
|
|
import "./Jobs/ScheduledMaintenancePublicNote/SendNotificationToSubscribers";
|
|
|
|
import "./Jobs/ScheduledMaintenanceStateTimeline/SendNotificationToSubscribers";
|
2024-09-20 22:42:38 +00:00
|
|
|
|
2024-09-22 10:46:46 +00:00
|
|
|
import "./Jobs/ServerMonitor/CheckOnlineStatus";
|
2024-09-10 15:25:58 +00:00
|
|
|
|
2024-09-21 14:03:16 +00:00
|
|
|
// // Certs Routers
|
2024-09-22 10:46:46 +00:00
|
|
|
import "./Jobs/StatusPageCerts/StatusPageCerts";
|
2024-09-21 16:35:36 +00:00
|
|
|
|
|
|
|
// Status Page Announcements
|
2024-09-21 19:06:22 +00:00
|
|
|
import "./Jobs/StatusPageOwners/SendAnnouncementCreatedNotification";
|
2024-09-21 15:01:50 +00:00
|
|
|
|
|
|
|
// Status Page Owners
|
2024-09-21 19:06:22 +00:00
|
|
|
import "./Jobs/StatusPageOwners/SendCreatedResourceNotification";
|
|
|
|
import "./Jobs/StatusPageOwners/SendOwnerAddedNotification";
|
2024-09-21 14:03:16 +00:00
|
|
|
|
2024-09-21 14:47:55 +00:00
|
|
|
// Status Page Reports
|
2024-09-22 12:08:46 +00:00
|
|
|
import "./Jobs/StatusPage/SendReportsToSubscribers";
|
2024-09-21 20:07:12 +00:00
|
|
|
|
2024-09-21 14:47:55 +00:00
|
|
|
// Telemetry Service
|
2024-09-21 20:07:12 +00:00
|
|
|
import "./Jobs/TelemetryService/DeleteOldData";
|
2024-09-21 16:05:05 +00:00
|
|
|
|
2024-09-21 14:47:55 +00:00
|
|
|
// User Notifications Log
|
2024-09-21 19:39:04 +00:00
|
|
|
import "./Jobs/UserOnCallLog/ExecutePendingExecutions";
|
|
|
|
import "./Jobs/UserOnCallLog/TimeoutStuckExecutions";
|
|
|
|
import "./Jobs/Workflow/TimeoutJobs";
|
2024-09-21 14:03:16 +00:00
|
|
|
|
2024-09-21 14:47:55 +00:00
|
|
|
// Probes
|
2024-09-22 10:14:30 +00:00
|
|
|
import "./Jobs/Probe/SendOwnerAddedNotification";
|
|
|
|
import "./Jobs/Probe/UpdateConnectionStatus";
|
2024-09-21 14:03:16 +00:00
|
|
|
|
2024-09-21 14:47:55 +00:00
|
|
|
// Copilot Actions.
|
2024-09-22 10:32:40 +00:00
|
|
|
import "./Jobs/CopilotActions/MoveThemBackToQueueIfProcessingForLongtime";
|
2024-09-21 14:47:55 +00:00
|
|
|
|
|
|
|
// Telemetry Monitors.
|
2024-09-21 20:07:12 +00:00
|
|
|
import "./Jobs/TelemetryMonitor/MonitorTelemetryMonitor";
|
2024-09-21 14:03:16 +00:00
|
|
|
|
2024-06-14 11:09:53 +00:00
|
|
|
import AnalyticsTableManagement from "./Utils/AnalyticsDatabase/TableManegement";
|
|
|
|
import RunDatabaseMigrations from "./Utils/DataMigration";
|
|
|
|
import JobDictionary from "./Utils/JobDictionary";
|
|
|
|
import { PromiseVoidFunction } from "Common/Types/FunctionTypes";
|
2024-08-20 20:59:26 +00:00
|
|
|
import Queue, { QueueJob, QueueName } from "Common/Server/Infrastructure/Queue";
|
2024-08-07 21:50:32 +00:00
|
|
|
import QueueWorker from "Common/Server/Infrastructure/QueueWorker";
|
|
|
|
import FeatureSet from "Common/Server/Types/FeatureSet";
|
|
|
|
import logger from "Common/Server/Utils/Logger";
|
2024-01-11 10:49:55 +00:00
|
|
|
|
2024-08-20 20:59:26 +00:00
|
|
|
import Express, { ExpressApplication } from "Common/Server/Utils/Express";
|
|
|
|
import ClusterKeyAuthorization from "Common/Server/Middleware/ClusterKeyAuthorization";
|
|
|
|
|
|
|
|
const app: ExpressApplication = Express.getExpressApp();
|
2024-08-05 21:40:20 +00:00
|
|
|
|
2024-01-11 13:55:07 +00:00
|
|
|
const WorkersFeatureSet: FeatureSet = {
|
2024-06-14 11:09:53 +00:00
|
|
|
init: async (): Promise<void> => {
|
|
|
|
try {
|
2024-09-21 14:03:16 +00:00
|
|
|
// attach bull board to the app
|
|
|
|
app.use(
|
|
|
|
Queue.getInspectorRoute(),
|
|
|
|
ClusterKeyAuthorization.isAuthorizedServiceMiddleware,
|
|
|
|
Queue.getQueueInspectorRouter(),
|
|
|
|
);
|
|
|
|
|
2024-06-14 11:09:53 +00:00
|
|
|
// run async database migrations
|
|
|
|
RunDatabaseMigrations().catch((err: Error) => {
|
|
|
|
logger.error("Error running database migrations");
|
|
|
|
logger.error(err);
|
|
|
|
});
|
2024-01-11 10:55:58 +00:00
|
|
|
|
2024-06-14 11:09:53 +00:00
|
|
|
// create tables in analytics database
|
|
|
|
await AnalyticsTableManagement.createTables();
|
2024-01-11 10:55:58 +00:00
|
|
|
|
2024-06-14 11:09:53 +00:00
|
|
|
// Job process.
|
|
|
|
QueueWorker.getWorker(
|
|
|
|
QueueName.Worker,
|
|
|
|
async (job: QueueJob) => {
|
|
|
|
const name: string = job.name;
|
2024-01-11 10:55:58 +00:00
|
|
|
|
2024-06-14 11:09:53 +00:00
|
|
|
logger.debug("Running Job: " + name);
|
2024-01-11 10:55:58 +00:00
|
|
|
|
2024-06-14 11:09:53 +00:00
|
|
|
const funcToRun: PromiseVoidFunction =
|
|
|
|
JobDictionary.getJobFunction(name);
|
2024-01-11 10:55:58 +00:00
|
|
|
|
2024-09-21 15:01:50 +00:00
|
|
|
const timeoutInMs: number = JobDictionary.getTimeoutInMs(name);
|
2024-08-27 12:33:15 +00:00
|
|
|
|
2024-06-14 11:09:53 +00:00
|
|
|
if (funcToRun) {
|
2024-09-21 15:01:50 +00:00
|
|
|
await QueueWorker.runJobWithTimeout(timeoutInMs, funcToRun);
|
2024-06-14 11:09:53 +00:00
|
|
|
}
|
|
|
|
},
|
2024-08-20 20:21:39 +00:00
|
|
|
{ concurrency: 100 },
|
2024-06-14 11:09:53 +00:00
|
|
|
);
|
|
|
|
} catch (err) {
|
|
|
|
logger.error("App Init Failed:");
|
|
|
|
logger.error(err);
|
|
|
|
throw err;
|
|
|
|
}
|
|
|
|
},
|
2024-01-11 12:17:41 +00:00
|
|
|
};
|
2024-01-11 10:49:55 +00:00
|
|
|
|
2024-01-11 10:55:58 +00:00
|
|
|
export default WorkersFeatureSet;
|