Skip to content

Instantly share code, notes, and snippets.

@mattfysh
Created February 26, 2024 07:25
Show Gist options
  • Save mattfysh/ff3abbd883d21b8fde2c11999f7c3fd2 to your computer and use it in GitHub Desktop.
Save mattfysh/ff3abbd883d21b8fde2c11999f7c3fd2 to your computer and use it in GitHub Desktop.
const mf = new Miniflare({
script: `
export default {
async fetch(request, env, ctx) {
let id = env.DOO.idFromName('foo')
return await env.DOO.get(id).fetch(request)
}
}
const SECONDS = 1000
export class Doo {
constructor(state) {
this.storage = state.storage
}
async fetch(request) {
this.storage.setAlarm(Date.now() + 1 * SECONDS)
return new Response('Hello Miniflare!')
}
async alarm() {
console.log("Alarm running")
}
}
`,
durableObjects: { DOO: 'Doo' },
log: new Log(),
verbose: true,
modules: true,
})
const response = await mf.dispatchFetch('http://localhost:8787/')
console.log(await response.text()) // Hello Miniflare!
@mattfysh
Copy link
Author

mattfysh commented Feb 26, 2024

Error message appears when the alarm is invoked, not when calling setAlarm

2024-02-26 17:24:48 workerd/io/worker-entrypoint.c++:561: warning: NOSENTRY Invalid alarm timeout value. Using 30 minutes; timeout = 0ns
2024-02-26 17:24:48 Alarm running

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment