mirror your GitHub repos to tangled.org automatically
1/**
2 * Trigger the worker tick endpoint locally.
3 *
4 * Reads `CRON_SECRET` from `.env` (loaded by Node's --env-file when run via
5 * `pnpm jobs:tick`) and GETs /api/jobs/run with the matching
6 * `Authorization: Bearer …` header — the same shape Vercel Cron sends.
7 *
8 * In production, Vercel Cron does this automatically; this script is the
9 * local equivalent.
10 */
11
12import process from 'node:process'
13
14const url = process.env.JOBS_TICK_URL ?? 'http://127.0.0.1:3000/api/jobs/run'
15const secret = process.env.CRON_SECRET
16
17if (!secret) {
18 console.error('CRON_SECRET not set; copy from .env or run `pnpm gen:cron-secret`')
19 process.exit(1)
20}
21
22const response = await fetch(url, {
23 method: 'GET',
24 headers: { authorization: `Bearer ${secret}` },
25})
26
27const body = await response.text()
28if (!response.ok) {
29 console.error(`worker tick failed with ${response.status}: ${body}`)
30 process.exit(1)
31}
32
33console.log(body)