mirror of
https://github.com/michivonah/themepark-assistant.git
synced 2025-12-22 22:16:29 +01:00
implement cron router + install cloudflare types
This commit is contained in:
parent
dfadc64afa
commit
3f9547f014
5 changed files with 7509 additions and 1 deletions
22
README.md
22
README.md
|
|
@ -14,4 +14,26 @@ DB scheme is defined in typescript
|
||||||
apply changes
|
apply changes
|
||||||
```bash
|
```bash
|
||||||
npx drizzle-kit push
|
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=*+*+*+*+*"
|
||||||
```
|
```
|
||||||
|
|
@ -2,6 +2,7 @@ import { Hono } from 'hono'
|
||||||
import { bearerAuth } from 'hono/bearer-auth'
|
import { bearerAuth } from 'hono/bearer-auth'
|
||||||
import notification from './notification'
|
import notification from './notification'
|
||||||
import logbook from './logbook'
|
import logbook from './logbook'
|
||||||
|
import cronRouter from './jobs/cron'
|
||||||
|
|
||||||
// create app
|
// create app
|
||||||
const app = new Hono()
|
const app = new Hono()
|
||||||
|
|
@ -14,4 +15,7 @@ app.use('/*', bearerAuth({ token }))
|
||||||
// define routes & export app
|
// define routes & export app
|
||||||
app.route('/notification', notification)
|
app.route('/notification', notification)
|
||||||
app.route('/logbook', logbook)
|
app.route('/logbook', logbook)
|
||||||
export default app
|
export default {
|
||||||
|
fetch: app.fetch,
|
||||||
|
scheduled: cronRouter,
|
||||||
|
}
|
||||||
|
|
|
||||||
17
api/src/jobs/cron.ts
Normal file
17
api/src/jobs/cron.ts
Normal 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
7459
api/worker-configuration.d.ts
vendored
Normal file
File diff suppressed because it is too large
Load diff
|
|
@ -29,6 +29,12 @@
|
||||||
"migrations_dir": "drizzle/migrations"
|
"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": {
|
// "ai": {
|
||||||
// "binding": "AI"
|
// "binding": "AI"
|
||||||
// },
|
// },
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue