add a feature flag to toggle primary worker processing jobs or not
This commit is contained in:
1 parent
d2461ef118
commit
ae4c433246
6 files changed
+22
-19
No files matched your search
@@ -1,5 +1,5 @@
|
|||||||
import { z } from "zod";
|
import { boolean, z } from "zod";
|
||||||
import { DbTypes, QueueTypes, QueueModes } from "@/domain/app-settings/app-settings.type.js";
|
import { DbTypes, QueueModes } from "@/domain/app-settings/app-settings.type.js";
|
||||||
import { booleanCoercion } from "@/api/validation/shared.js";
|
import { booleanCoercion } from "@/api/validation/shared.js";
|
||||||
|
|
||||||
const envSchema = z.object({
|
const envSchema = z.object({
|
||||||
@@ -12,8 +12,8 @@ const envSchema = z.object({
|
|||||||
DB_CONNECTION_STRING: z.string().min(1, "Database connection string is required"),
|
DB_CONNECTION_STRING: z.string().min(1, "Database connection string is required"),
|
||||||
DB_TYPE: z.enum(DbTypes).default("mongodb"),
|
DB_TYPE: z.enum(DbTypes).default("mongodb"),
|
||||||
|
|
||||||
QUEUE_TYPE: z.enum(QueueTypes).default("superSimpleQueue"),
|
|
||||||
QUEUE_MODE: z.enum(QueueModes).default("primary"),
|
QUEUE_MODE: z.enum(QueueModes).default("primary"),
|
||||||
|
QUEUE_PRIMARY_PROCESSES: booleanCoercion.default(true),
|
||||||
|
|
||||||
// JWT Authentication
|
// JWT Authentication
|
||||||
JWT_SECRET: z.string().min(1, "JWT_SECRET is required"),
|
JWT_SECRET: z.string().min(1, "JWT_SECRET is required"),
|
||||||
|
|||||||
@@ -301,7 +301,8 @@ export const initializeServices = async ({
|
|||||||
geoCheckPipeline,
|
geoCheckPipeline,
|
||||||
reactorDispatcher,
|
reactorDispatcher,
|
||||||
workerHelper,
|
workerHelper,
|
||||||
envSettings.queueMode
|
envSettings.queueMode,
|
||||||
|
envSettings.queuePrimaryProcesses
|
||||||
);
|
);
|
||||||
|
|
||||||
// Business services
|
// Business services
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { ISettingsRepository } from "@/domain/app-settings/app-settings-repository.interface.js";
|
import { ISettingsRepository } from "@/domain/app-settings/app-settings-repository.interface.js";
|
||||||
import { Settings, SettingsUpdate, type DbType, type QueueMode, type QueueType } from "@/domain/app-settings/app-settings.type.js";
|
import { Settings, SettingsUpdate, type DbType, type QueueMode } from "@/domain/app-settings/app-settings.type.js";
|
||||||
import { AppError } from "@/utils/AppError.js";
|
import { AppError } from "@/utils/AppError.js";
|
||||||
import { ValidatedEnv } from "@/config/envValidation.js";
|
import { ValidatedEnv } from "@/config/envValidation.js";
|
||||||
import type { StringValue } from "ms";
|
import type { StringValue } from "ms";
|
||||||
@@ -13,8 +13,8 @@ export type EnvConfig = {
|
|||||||
clientHost: string;
|
clientHost: string;
|
||||||
dbConnectionString: string;
|
dbConnectionString: string;
|
||||||
dbType: DbType;
|
dbType: DbType;
|
||||||
queueType: QueueType;
|
|
||||||
queueMode: QueueMode;
|
queueMode: QueueMode;
|
||||||
|
queuePrimaryProcesses: boolean;
|
||||||
statusPageThemesEnabled: boolean;
|
statusPageThemesEnabled: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -41,8 +41,8 @@ export class SettingsService implements ISettingsService {
|
|||||||
clientHost: env.CLIENT_HOST,
|
clientHost: env.CLIENT_HOST,
|
||||||
dbConnectionString: env.DB_CONNECTION_STRING,
|
dbConnectionString: env.DB_CONNECTION_STRING,
|
||||||
dbType: env.DB_TYPE,
|
dbType: env.DB_TYPE,
|
||||||
queueType: env.QUEUE_TYPE,
|
|
||||||
queueMode: env.QUEUE_MODE,
|
queueMode: env.QUEUE_MODE,
|
||||||
|
queuePrimaryProcesses: env.QUEUE_PRIMARY_PROCESSES,
|
||||||
statusPageThemesEnabled: env.STATUS_PAGE_THEMES_ENABLED,
|
statusPageThemesEnabled: env.STATUS_PAGE_THEMES_ENABLED,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +1,6 @@
|
|||||||
export const DbTypes = ["mongodb"] as const;
|
export const DbTypes = ["mongodb"] as const;
|
||||||
export type DbType = (typeof DbTypes)[number];
|
export type DbType = (typeof DbTypes)[number];
|
||||||
|
|
||||||
export const QueueTypes = ["lessSimpleQueue", "superSimpleQueue", "dbQueue"] as const;
|
|
||||||
export type QueueType = (typeof QueueTypes)[number];
|
|
||||||
|
|
||||||
export const QueueModes = ["primary", "worker"] as const;
|
export const QueueModes = ["primary", "worker"] as const;
|
||||||
export type QueueMode = (typeof QueueModes)[number];
|
export type QueueMode = (typeof QueueModes)[number];
|
||||||
|
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ import { ICheckEvaluator } from "@/worker/worker.check-evaluator.js";
|
|||||||
import { ICheckPipeline } from "@/worker/worker.check-pipeline.js";
|
import { ICheckPipeline } from "@/worker/worker.check-pipeline.js";
|
||||||
import { IReactorDispatcher } from "@/worker/reactors/reactor.dispatcher.js";
|
import { IReactorDispatcher } from "@/worker/reactors/reactor.dispatcher.js";
|
||||||
import { IWorkerHelper } from "@/worker/worker.helper.js";
|
import { IWorkerHelper } from "@/worker/worker.helper.js";
|
||||||
import { QueueMode, QueueModes } from "@/domain/app-settings/app-settings.type.js";
|
import { QueueMode } from "@/domain/app-settings/app-settings.type.js";
|
||||||
const SERVICE_NAME = "JobQueue";
|
const SERVICE_NAME = "JobQueue";
|
||||||
const POLL_MS = 250;
|
const POLL_MS = 250;
|
||||||
const CLEANUP_INTERVAL_MS = 24 * 60 * 60 * 1000;
|
const CLEANUP_INTERVAL_MS = 24 * 60 * 60 * 1000;
|
||||||
@@ -49,7 +49,8 @@ export class DBQueueWorker implements IWorker {
|
|||||||
private geoCheckPipeline: ICheckPipeline,
|
private geoCheckPipeline: ICheckPipeline,
|
||||||
private dispatcher: IReactorDispatcher,
|
private dispatcher: IReactorDispatcher,
|
||||||
private helper: IWorkerHelper,
|
private helper: IWorkerHelper,
|
||||||
private mode: QueueMode
|
private queueMode: QueueMode,
|
||||||
|
private queuePrimaryProcesses: boolean
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
get serviceName() {
|
get serviceName() {
|
||||||
@@ -67,7 +68,8 @@ export class DBQueueWorker implements IWorker {
|
|||||||
geoCheckPipeline: ICheckPipeline,
|
geoCheckPipeline: ICheckPipeline,
|
||||||
dispatcher: IReactorDispatcher,
|
dispatcher: IReactorDispatcher,
|
||||||
helper: IWorkerHelper,
|
helper: IWorkerHelper,
|
||||||
mode: QueueMode
|
queueMode: QueueMode,
|
||||||
|
queuePrimaryProcesses: boolean
|
||||||
): Promise<DBQueueWorker> {
|
): Promise<DBQueueWorker> {
|
||||||
const instance = new DBQueueWorker(
|
const instance = new DBQueueWorker(
|
||||||
logger,
|
logger,
|
||||||
@@ -80,7 +82,8 @@ export class DBQueueWorker implements IWorker {
|
|||||||
geoCheckPipeline,
|
geoCheckPipeline,
|
||||||
dispatcher,
|
dispatcher,
|
||||||
helper,
|
helper,
|
||||||
mode
|
queueMode,
|
||||||
|
queuePrimaryProcesses
|
||||||
);
|
);
|
||||||
await instance.init();
|
await instance.init();
|
||||||
return instance;
|
return instance;
|
||||||
@@ -246,16 +249,19 @@ export class DBQueueWorker implements IWorker {
|
|||||||
|
|
||||||
init = async () => {
|
init = async () => {
|
||||||
this.stopped = false;
|
this.stopped = false;
|
||||||
if (this.mode === "primary") {
|
|
||||||
|
if (this.queueMode === "primary") {
|
||||||
await this.reconcile();
|
await this.reconcile();
|
||||||
return true;
|
}
|
||||||
} else {
|
|
||||||
|
if (this.queuePrimaryProcesses === true || this.queueMode === "worker") {
|
||||||
for (const type of Object.keys(this.inFlight) as JobType[]) {
|
for (const type of Object.keys(this.inFlight) as JobType[]) {
|
||||||
this.startLoop(type);
|
this.startLoop(type);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
|
|
||||||
addJob = async (_monitorId: string, monitor: Monitor) => {
|
addJob = async (_monitorId: string, monitor: Monitor) => {
|
||||||
const now = Date.now();
|
const now = Date.now();
|
||||||
await this.jobsRepository.upsertJob(this.toCheckJob(monitor, now));
|
await this.jobsRepository.upsertJob(this.toCheckJob(monitor, now));
|
||||||
@@ -315,7 +321,7 @@ export class DBQueueWorker implements IWorker {
|
|||||||
jobsWithFailures: [],
|
jobsWithFailures: [],
|
||||||
totalRuns: 0,
|
totalRuns: 0,
|
||||||
totalFailures: 0,
|
totalFailures: 0,
|
||||||
workers: [{ workerId: this.workerId, mode: this.mode, lastSeenAt: now }],
|
workers: [{ workerId: this.workerId, mode: this.queueMode, lastSeenAt: now }],
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
import { Monitor } from "@/domain/monitors/monitor.types.js";
|
import { Monitor } from "@/domain/monitors/monitor.types.js";
|
||||||
import { QueueWorker } from "@/domain/queue-workers/queue-worker.type.js";
|
|
||||||
import { Check } from "@/domain/checks/check.type.js";
|
import { Check } from "@/domain/checks/check.type.js";
|
||||||
import { MonitorPayloadMap, MonitorStatusResponse, StatusChangeResult } from "@/types/network.js";
|
import { MonitorPayloadMap, MonitorStatusResponse, StatusChangeResult } from "@/types/network.js";
|
||||||
import { MonitorActionDecision } from "@/worker/worker.helper.js";
|
import { MonitorActionDecision } from "@/worker/worker.helper.js";
|
||||||
|
|||||||
Reference in new issue
Block a user