implement cron router + install cloudflare types

This commit is contained in:
Michi 2025-09-13 11:37:01 +02:00
parent dfadc64afa
commit 3f9547f014
5 changed files with 7509 additions and 1 deletions

View file

@ -15,3 +15,25 @@ apply changes
```bash
npx drizzle-kit push
```
## Cloudflare workers tricks
If types are missing, run:
```bash
npx wrangler types
```
## Testing cronjobs
Run worker locally (without remote d1 access)
```bash
npx wrangler dev --test-scheduled
```
Run worker locally (with remote connection to d1)
```bash
npx wrangler dev --remote --test-scheduled
```
Run curl request with cron expression
```bash
curl "http://localhost:8787/__scheduled?cron=*+*+*+*+*"
```

View file

@ -2,6 +2,7 @@ import { Hono } from 'hono'
import { bearerAuth } from 'hono/bearer-auth'
import notification from './notification'
import logbook from './logbook'
import cronRouter from './jobs/cron'
// create app
const app = new Hono()
@ -14,4 +15,7 @@ app.use('/*', bearerAuth({ token }))
// define routes & export app
app.route('/notification', notification)
app.route('/logbook', logbook)
export default app
export default {
fetch: app.fetch,
scheduled: cronRouter,
}

17
api/src/jobs/cron.ts Normal file
View file

@ -0,0 +1,17 @@
// Cron Router
import { updateThemeparkData } from "./update-themepark-data";
export default async function cronRouter(
event: ScheduledEvent,
env: Env,
ctx: ExecutionContext,
){
switch (event.cron){
case '* * * * *':
console.log('every minute');
break;
default:
console.log('its me - the cron router');
break;
}
}

7459
api/worker-configuration.d.ts vendored Normal file

File diff suppressed because it is too large Load diff

View file

@ -29,6 +29,12 @@
"migrations_dir": "drizzle/migrations"
}
],
"triggers": {
"crons": [
"0 4 7,14,21,28 * *", // At 04:00 on day-of-month 7, 14, 21, and 28.
"* * * * *" // every minute
]
}
// "ai": {
// "binding": "AI"
// },