cron not running locally on the trigger specified

I'm using hono here but when i go to http://localhost:8787/__scheduled?cron=***** i see the response log
Hello
[wrangler:inf] GET /__scheduled 200 OK (11ms)
╭─────────────────────────────────────────────────────
Hello
[wrangler:inf] GET /__scheduled 200 OK (11ms)
╭─────────────────────────────────────────────────────
but I dont see anymore subsequent logs of the trigger again. am i doing anything wrong?
async function scheduledHandler(
event: ScheduledEvent,
env: Env,
ctx: ExecutionContext,
) {
const testMessages = [
'Hello',
'Goodbye',
'Welcome',
'Farewell',
'Greetings',
'I am leaving',
]
ctx.waitUntil(
(async () => {
const randomIndex = Math.floor(Math.random() * testMessages.length)
const randomMessage = testMessages[randomIndex]
console.log(randomMessage)
})(),
)
}

export default { fetch: app.fetch.bind(app), scheduled: scheduledHandler }
async function scheduledHandler(
event: ScheduledEvent,
env: Env,
ctx: ExecutionContext,
) {
const testMessages = [
'Hello',
'Goodbye',
'Welcome',
'Farewell',
'Greetings',
'I am leaving',
]
ctx.waitUntil(
(async () => {
const randomIndex = Math.floor(Math.random() * testMessages.length)
const randomMessage = testMessages[randomIndex]
console.log(randomMessage)
})(),
)
}

export default { fetch: app.fetch.bind(app), scheduled: scheduledHandler }
3 Replies
DiamondDragon
DiamondDragonOP8mo ago
i deployed and am seeing the logs so maybe local dev has an issue with running triggers?
"*/3 * * * *" @ 4/13/2024, 1:42:19 PM - Ok
(log) Running scheduled event {"cron":"*/3 * * * *","scheduledTime":1713040939000} with ctx {}
(log) Greetings
"*/3 * * * *" @ 4/13/2024, 1:45:19 PM - Ok
(log) Running scheduled event {"cron":"*/3 * * * *","scheduledTime":1713041119000} with ctx {}
(log) Farewell
"*/3 * * * *" @ 4/13/2024, 1:42:19 PM - Ok
(log) Running scheduled event {"cron":"*/3 * * * *","scheduledTime":1713040939000} with ctx {}
(log) Greetings
"*/3 * * * *" @ 4/13/2024, 1:45:19 PM - Ok
(log) Running scheduled event {"cron":"*/3 * * * *","scheduledTime":1713041119000} with ctx {}
(log) Farewell
James
James8mo ago
Cron triggers in local mode have some caveats today. You need to pass —scheduled, and they won’t run automatically. This doc highlights this and is a good reference for other features too: https://docs.google.com/spreadsheets/d/1T7j7FZZO7zmkrEegzhMeMtlFPIh-efYGMc7BuenMPWY/edit?usp=sharing
Sohaib Muhammad
Sohaib Muhammad8mo ago
can you please share fetch handler code because i am always getting 404 when working with Hono
Want results from more Discord servers?
Add your server