chore: initial project import
Some checks failed
CI - Production Readiness / Verify (push) Has been cancelled

This commit is contained in:
Wira Basalamah
2026-04-21 09:29:29 +07:00
commit adde003fba
222 changed files with 37657 additions and 0 deletions

52
lib/job-alerts.ts Normal file
View File

@ -0,0 +1,52 @@
type CampaignRetryFailureAlert = {
jobName: string;
runId: string;
error: string;
runAt: string;
tenantId?: string;
campaignId?: string;
processedCampaigns: number;
totalAttempted: number;
totalFailed: number;
};
function normalizeWebhookEnabled() {
const raw = process.env.CAMPAIGN_RETRY_ALERT_WEBHOOK_URL?.trim();
return raw ? raw : "";
}
function normalizeBoolean(value: string | undefined) {
if (!value) {
return true;
}
return ["1", "true", "yes", "on"].includes(value.trim().toLowerCase());
}
export async function notifyCampaignRetryFailure(payload: CampaignRetryFailureAlert) {
const webhookUrl = normalizeWebhookEnabled();
if (!webhookUrl) {
return;
}
const shouldNotify = normalizeBoolean(process.env.CAMPAIGN_RETRY_ALERT_ON_FAILURE);
if (!shouldNotify) {
return;
}
const message = {
event: "campaign_retry_job_failed",
...payload,
timestamp: new Date().toISOString()
};
try {
await fetch(webhookUrl, {
method: "POST",
headers: { "content-type": "application/json" },
body: JSON.stringify(message)
});
} catch {
// observability channel should not block retries
}
}