Track HiveGrid Cloud planning reference
This commit is contained in:
1 parent
b3d5ea6764
commit
e341c5938a
5784 files changed
+1104929
-3
No files matched your search
@@ -0,0 +1,74 @@
|
||||
import type { EnvRecord } from "@toolctrl/config";
|
||||
|
||||
import {
|
||||
FORM_SUBMISSION_WEBHOOK_OUTBOX_QUEUE,
|
||||
runFormSubmissionWebhookDeliveryJob,
|
||||
type FormSubmissionWebhookDeliveryDeps,
|
||||
} from "./form-submission-webhook-delivery.js";
|
||||
import type { FormSubmissionRouteLogger } from "./form-submission-route.js";
|
||||
|
||||
export type FormSubmissionWebhookDeliveryBootstrapEnv = EnvRecord & {
|
||||
WORKER_QUEUE_GROUP?: string;
|
||||
FORM_SUBMISSION_WEBHOOK_DELIVERY_ENABLED?: string;
|
||||
FORM_SUBMISSION_WEBHOOK_DELIVERY_CONCURRENCY?: string;
|
||||
};
|
||||
|
||||
export interface FormSubmissionWebhookDeliveryWorkerHandle {
|
||||
readonly name: string;
|
||||
close(): Promise<void>;
|
||||
}
|
||||
|
||||
export interface FormSubmissionWebhookDeliveryBootstrapDeps {
|
||||
readonly logger?: FormSubmissionRouteLogger;
|
||||
readonly handlerDeps?: FormSubmissionWebhookDeliveryDeps;
|
||||
readonly createWorkerImpl?: (
|
||||
queueName: string,
|
||||
processor: (job: { data: unknown }) => Promise<unknown>,
|
||||
options: { concurrency?: number },
|
||||
) => FormSubmissionWebhookDeliveryWorkerHandle;
|
||||
}
|
||||
|
||||
export type FormSubmissionWebhookDeliveryBootstrapResult =
|
||||
| { readonly status: "disabled"; readonly reason: string }
|
||||
| { readonly status: "started"; readonly handle: FormSubmissionWebhookDeliveryWorkerHandle };
|
||||
|
||||
const DEFAULT_CONCURRENCY = 5;
|
||||
|
||||
function parsePositiveInt(value: unknown, fallback: number): number {
|
||||
if (typeof value !== "string" || value.length === 0) return fallback;
|
||||
const parsed = Number.parseInt(value, 10);
|
||||
return Number.isFinite(parsed) && parsed > 0 ? parsed : fallback;
|
||||
}
|
||||
|
||||
export function bootstrapFormSubmissionWebhookDelivery(
|
||||
env: FormSubmissionWebhookDeliveryBootstrapEnv,
|
||||
deps: FormSubmissionWebhookDeliveryBootstrapDeps = {},
|
||||
): FormSubmissionWebhookDeliveryBootstrapResult {
|
||||
if (env.WORKER_QUEUE_GROUP && env.WORKER_QUEUE_GROUP !== "mail") {
|
||||
return { status: "disabled", reason: "non-mail worker group" };
|
||||
}
|
||||
if (env.FORM_SUBMISSION_WEBHOOK_DELIVERY_ENABLED === "false") {
|
||||
return { status: "disabled", reason: "FORM_SUBMISSION_WEBHOOK_DELIVERY_ENABLED=false" };
|
||||
}
|
||||
if (!deps.handlerDeps) {
|
||||
return { status: "disabled", reason: "no handler deps wired (host must supply webhook enqueue)" };
|
||||
}
|
||||
if (!deps.createWorkerImpl) {
|
||||
return { status: "disabled", reason: "no worker factory wired" };
|
||||
}
|
||||
|
||||
const concurrency = parsePositiveInt(env.FORM_SUBMISSION_WEBHOOK_DELIVERY_CONCURRENCY, DEFAULT_CONCURRENCY);
|
||||
const handlerDeps = deps.handlerDeps;
|
||||
const processor = (job: { data: unknown }) => runFormSubmissionWebhookDeliveryJob(job.data, handlerDeps);
|
||||
const handle = deps.createWorkerImpl(FORM_SUBMISSION_WEBHOOK_OUTBOX_QUEUE, processor, { concurrency });
|
||||
|
||||
deps.logger?.info?.(
|
||||
{
|
||||
component: "form-submission-webhook-delivery",
|
||||
queue: FORM_SUBMISSION_WEBHOOK_OUTBOX_QUEUE,
|
||||
concurrency,
|
||||
},
|
||||
"form-submission webhook delivery bridge started",
|
||||
);
|
||||
return { status: "started", handle };
|
||||
}
|
||||
Reference in new issue
Block a user