({
userId,
type,
delayDays,
}: ScheduleLifecycleEmailOptions)
| 22 | * Uses Trigger.dev's built-in delay scheduling — no polling or cron needed. |
| 23 | */ |
| 24 | export async function scheduleLifecycleEmail({ |
| 25 | userId, |
| 26 | type, |
| 27 | delayDays, |
| 28 | }: ScheduleLifecycleEmailOptions): Promise<void> { |
| 29 | if (!isTriggerDevEnabled || !env.TRIGGER_SECRET_KEY) { |
| 30 | logger.info('[lifecycle] Trigger.dev not configured, skipping lifecycle email', { |
| 31 | userId, |
| 32 | type, |
| 33 | }) |
| 34 | return |
| 35 | } |
| 36 | |
| 37 | const delayUntil = new Date(Date.now() + delayDays * 24 * 60 * 60 * 1000) |
| 38 | |
| 39 | await tasks.trigger( |
| 40 | LIFECYCLE_EMAIL_TASK_ID, |
| 41 | { userId, type }, |
| 42 | { |
| 43 | delay: delayUntil, |
| 44 | idempotencyKey: `lifecycle-${type}-${userId}`, |
| 45 | region: await resolveTriggerRegion(), |
| 46 | } |
| 47 | ) |
| 48 | |
| 49 | logger.info('[lifecycle] Scheduled lifecycle email', { userId, type, delayDays }) |
| 50 | } |
no test coverage detected