feat: add crm webhook worker

This commit is contained in:
Codex
2026-06-29 04:35:19 +08:00
parent 0cff0d102d
commit ead1296f80
23 changed files with 1098 additions and 14 deletions

25
apps/worker/src/config.ts Normal file
View File

@@ -0,0 +1,25 @@
import { DEFAULT_DATABASE_URL, envBoolean, envList, envNumber, envString, loadDotenv } from '../../../packages/config/src/index.js';
loadDotenv();
export interface WorkerConfig {
databaseUrl: string;
crmBatchSize: number;
crmPollIntervalMs: number;
crmMaxAttempts: number;
crmBackoffSeconds: number[];
crmRequestTimeoutMs: number;
crmAllowInsecureLocalhost: boolean;
}
export const config: WorkerConfig = {
databaseUrl: envString('DATABASE_URL', DEFAULT_DATABASE_URL),
crmBatchSize: envNumber('WORKER_CRM_BATCH_SIZE', 20),
crmPollIntervalMs: envNumber('WORKER_CRM_POLL_INTERVAL_MS', 10_000),
crmMaxAttempts: envNumber('WORKER_CRM_MAX_ATTEMPTS', 5),
crmBackoffSeconds: envList('WORKER_CRM_BACKOFF_SECONDS', '5,30,120,600,1800')
.map((value: string) => Number(value))
.filter((value: number) => Number.isFinite(value) && value > 0),
crmRequestTimeoutMs: envNumber('WORKER_CRM_REQUEST_TIMEOUT_MS', 10_000),
crmAllowInsecureLocalhost: envBoolean('WORKER_CRM_ALLOW_INSECURE_LOCALHOST', false),
};