Skip to content

Commit

Permalink
Better types for scheduled handler
Browse files Browse the repository at this point in the history
  • Loading branch information
rmarscher committed Feb 1, 2024
1 parent 1586e49 commit 8392b25
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions packages/api/src/scheduled.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { match } from 'ts-pattern'
import { createContext } from './context'

const scheduled: ExportedHandlerScheduledHandler<Bindings> = async (event, env, _) => {
const ctx = await createContext(env)
console.log('Running cron', event.cron)
await match({ event, ctx })
.with({ event: { cron: '15 2 0 * *' } }, async ({ ctx }) => {
await ctx.auth.deleteExpiredSessions()
console.log('Deleted expired sessions')
})
.otherwise(async () => {
console.log('Unhandled cron event', event)
})
}

export default scheduled

0 comments on commit 8392b25

Please sign in to comment.