File size: 1,767 Bytes
68d7816 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 | import { type ConfigStripEnv, type EnvBindings, envBindings } from '#/app/config/config';
import { registerConfigSection } from '#/app/config/configSectionContributions';
export const CRON_SECTION = 'cron';
export interface CronConfig {
readonly debug: boolean;
readonly noJitter: boolean;
readonly noStale: boolean;
readonly disabled: boolean;
readonly manualTick: boolean;
readonly clock?: string;
readonly pollIntervalMs?: number | null;
}
export const DEFAULT_CRON_CONFIG: CronConfig = {
debug: false,
noJitter: false,
noStale: false,
disabled: false,
manualTick: false,
};
const cronConfigSchema = { parse: (value: unknown): CronConfig => value as CronConfig };
const on = (raw: string): boolean => raw === '1';
function parsePollIntervalMs(raw: string): number | null | undefined {
const value = raw.trim();
if (value.length === 0) return undefined;
if (value === 'null') return null;
const parsed = Number(value);
if (!Number.isFinite(parsed) || !Number.isInteger(parsed) || parsed < 0) return undefined;
return parsed;
}
export const cronEnvBindings: EnvBindings<CronConfig> = envBindings(cronConfigSchema, {
debug: { env: 'KIMI_CRON_DEBUG', parse: on },
noJitter: { env: 'KIMI_CRON_NO_JITTER', parse: on },
noStale: { env: 'KIMI_CRON_NO_STALE', parse: on },
disabled: { env: 'KIMI_DISABLE_CRON', parse: on },
manualTick: { env: 'KIMI_CRON_MANUAL_TICK', parse: on },
clock: 'KIMI_CRON_CLOCK',
pollIntervalMs: { env: 'KIMI_CRON_POLL_INTERVAL_MS', parse: parsePollIntervalMs },
});
export const stripCronEnv: ConfigStripEnv<CronConfig> = () => undefined;
registerConfigSection(CRON_SECTION, cronConfigSchema, {
defaultValue: DEFAULT_CRON_CONFIG,
env: cronEnvBindings,
stripEnv: stripCronEnv,
});
|