Files
oneuptime/App/FeatureSet/Workers/Index.ts
Nawaz Dhandala ea71c8bd75 feat: Implement Workflow API and Queue Management
- Added ManualAPI for manually triggering workflows via GET and POST requests.
- Introduced WorkflowAPI for updating workflows with authorization checks.
- Created documentation for JavaScript and Webhook components.
- Established WorkflowFeatureSet to initialize routing and job processing.
- Developed QueueWorkflow service for managing workflow queue operations.
- Implemented RunWorkflow service to execute workflows with error handling and logging.
- Added utility for loading component metadata dynamically.
2026-04-01 22:05:19 +01:00

211 lines
7.6 KiB
TypeScript

// Announcements.
import "./Jobs/Announcement/SendNotificationToSubscribers";
// Hard Delete
import "./Jobs/HardDelete/HardDeleteItemsInDatabase";
// Incidents
import "./Jobs/Incident/SendNotificationToSubscribers";
import "./Jobs/Incident/SendPostmortemNotificationToSubscribers";
import "./Jobs/Incident/KeepCurrentStateConsistent";
// Incident Owners
import "./Jobs/IncidentOwners/SendCreatedResourceNotification";
import "./Jobs/IncidentOwners/SendNotePostedNotification";
import "./Jobs/IncidentOwners/SendOwnerAddedNotification";
import "./Jobs/IncidentOwners/SendStateChangeNotification";
// Incident Members
import "./Jobs/IncidentMembers/SendMemberAddedNotification";
// Incident SLA
import "./Jobs/IncidentSla/CheckSlaBreaches";
import "./Jobs/IncidentSla/SendNoteReminders";
// Monitor Jobs.
import "./Jobs/Monitor/KeepCurrentStateConsistent";
// Alert Owners
import "./Jobs/AlertOwners/SendCreatedResourceNotification";
import "./Jobs/AlertOwners/SendNotePostedNotification";
import "./Jobs/AlertOwners/SendOwnerAddedNotification";
import "./Jobs/AlertOwners/SendStateChangeNotification";
import "./Jobs/Alert/KeepCurrentStateConsistent";
// Alert Episodes
import "./Jobs/AlertEpisode/AutoResolve";
import "./Jobs/AlertEpisode/ResolveInactiveEpisodes";
// Alert Episode Owners
import "./Jobs/AlertEpisodeOwners/SendCreatedResourceNotification";
import "./Jobs/AlertEpisodeOwners/SendNotePostedNotification";
import "./Jobs/AlertEpisodeOwners/SendOwnerAddedNotification";
import "./Jobs/AlertEpisodeOwners/SendStateChangeNotification";
// Incident Episodes
import "./Jobs/IncidentEpisode/AutoResolve";
import "./Jobs/IncidentEpisode/ResolveInactiveEpisodes";
import "./Jobs/IncidentEpisode/SendNotificationToSubscribers";
// Incident Episode State Timeline
import "./Jobs/IncidentEpisodeStateTimeline/SendNotificationToSubscribers";
// Incident Episode Public Notes
import "./Jobs/IncidentEpisodePublicNote/SendNotificationToSubscribers";
// Incident Episode Owners
import "./Jobs/IncidentEpisodeOwners/SendCreatedResourceNotification";
import "./Jobs/IncidentEpisodeOwners/SendNotePostedNotification";
import "./Jobs/IncidentEpisodeOwners/SendOwnerAddedNotification";
import "./Jobs/IncidentEpisodeOwners/SendStateChangeNotification";
// Incident Notes
import "./Jobs/IncidentPublicNote/SendNotificationToSubscribers";
import "./Jobs/IncidentStateTimeline/SendNotificationToSubscribers";
import "./Jobs/IncomingRequestMonitor/CheckHeartbeat";
import "./Jobs/IncomingEmailMonitor/CheckOnlineStatus";
import "./Jobs/MeteredPlan/ReportTelemetryMeteredPlan";
// 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";
// Scheduled Event
import "./Jobs/ScheduledMaintenance/ChangeStateToOngoing";
import "./Jobs/ScheduledMaintenance/SendNotificationToSubscribers";
import "./Jobs/ScheduledMaintenance/ScheduleRecurringEvents";
import "./Jobs/ScheduledMaintenance/SendSubscriberRemindersOnEventScheduled";
import "./Jobs/ScheduledMaintenance/KeepCurrentStateConsistent";
// Scheduled Event Owners
import "./Jobs/ScheduledMaintenanceOwners/SendCreatedResourceNotification";
import "./Jobs/ScheduledMaintenanceOwners/SendNotePostedNotification";
import "./Jobs/ScheduledMaintenanceOwners/SendOwnerAddedNotification";
import "./Jobs/ScheduledMaintenanceOwners/SendStateChangeNotification";
// Scheduled Event Notes
import "./Jobs/ScheduledMaintenancePublicNote/SendNotificationToSubscribers";
import "./Jobs/ScheduledMaintenanceStateTimeline/SendNotificationToSubscribers";
import "./Jobs/ServerMonitor/CheckOnlineStatus";
// // Certs Routers
import "./Jobs/StatusPageCerts/StatusPageCerts";
import "./Jobs/CoreSsl/ProvisionPrimaryDomain";
// Status Page Announcements
import "./Jobs/StatusPageOwners/SendAnnouncementCreatedNotification";
// Status Page Owners
import "./Jobs/StatusPageOwners/SendCreatedResourceNotification";
import "./Jobs/StatusPageOwners/SendOwnerAddedNotification";
// Status Page Reports
import "./Jobs/StatusPage/SendReportsToSubscribers";
// Workspace Notification Summaries
import "./Jobs/WorkspaceNotificationSummary/SendSummary";
// User Notifications Log
import "./Jobs/UserOnCallLog/ExecutePendingExecutions";
import "./Jobs/UserOnCallLog/TimeoutStuckExecutions";
import "./Jobs/Workflow/TimeoutJobs";
// Probes
import "./Jobs/Probe/SendOwnerAddedNotification";
import "./Jobs/Probe/UpdateConnectionStatus";
// AI Agents
import "./Jobs/AIAgent/SendOwnerAddedNotification";
import "./Jobs/AIAgent/UpdateConnectionStatus";
import "./Jobs/AIAgent/TimeoutStuckTasks";
// Telemetry Monitors.
import "./Jobs/TelemetryMonitor/MonitorTelemetryMonitor";
//Metric Jobs.
import "./Jobs/Metrics/DeleteMonitorMetricsOlderThanXDays";
import "./Jobs/Metrics/DeleteIncidentMetricOlderThanXDays";
import "./Jobs/Metrics/DeleteAlertMetricOlderThanXDays";
import "./Jobs/OnCallDutySchedule/RefreshHandoffTime";
/*
* DeleteMonitorLogOlderThan24Hours cron job removed — TTL via retentionDate column
* now handles automatic MonitorLog retention in ClickHouse. Retention days are read
* from GlobalConfig.monitorLogRetentionInDays at ingestion time in MonitorLogUtil.
*/
import "./Jobs/OnCallPolicy/DeleteOldTimeLogs";
import "./Jobs/PaymentProvider/SendDailyEmailsToOwnersIfSubscriptionIsOverdue";
import AnalyticsTableManagement from "./Utils/AnalyticsDatabase/TableManegement";
import RunDatabaseMigrations from "./Utils/DataMigration";
import JobDictionary from "./Utils/JobDictionary";
import { PromiseVoidFunction } from "Common/Types/FunctionTypes";
import Queue, { QueueJob, QueueName } from "Common/Server/Infrastructure/Queue";
import QueueWorker from "Common/Server/Infrastructure/QueueWorker";
import FeatureSet from "Common/Server/Types/FeatureSet";
import logger from "Common/Server/Utils/Logger";
import { WORKER_CONCURRENCY } from "./Config";
import MetricsAPI from "./API/Metrics";
import Express, { ExpressApplication } from "Common/Server/Utils/Express";
const app: ExpressApplication = Express.getExpressApp();
const WorkersFeatureSet: FeatureSet = {
init: async (): Promise<void> => {
try {
// attach bull board to the app
app.use(Queue.getInspectorRoute(), Queue.getQueueInspectorRouter());
// expose metrics endpoint used by KEDA
app.use(["/worker", "/"], MetricsAPI);
// run async database migrations
RunDatabaseMigrations().catch((err: Error) => {
logger.error("Error running database migrations");
logger.error(err);
});
// create tables in analytics database
await AnalyticsTableManagement.createTables();
// Job process.
QueueWorker.getWorker(
QueueName.Worker,
async (job: QueueJob) => {
const name: string = job.name;
logger.debug("Running Job: " + name);
const funcToRun: PromiseVoidFunction =
JobDictionary.getJobFunction(name);
const timeoutInMs: number = JobDictionary.getTimeoutInMs(name);
if (funcToRun) {
await QueueWorker.runJobWithTimeout(timeoutInMs, funcToRun);
}
},
{ concurrency: WORKER_CONCURRENCY },
);
} catch (err) {
logger.error("App Init Failed:");
logger.error(err);
throw err;
}
},
};
export default WorkersFeatureSet;