agents-0-22-0-12-b
Claude Code's read-only tools, web search on, ludion sync off
Question
Is the second argument of a this.schedule() callback the Schedule object?
Answer key
- A correct answer says
- A scheduled callback's second argument is the parsed `Schedule` object.
- The stale answer
- A scheduled callback's second argument is the raw storage row with `payload` as a JSON string.
Answer
Yes, assuming you mean the Cloudflare Agents SDK. When the alarm fires, the Agent calls your callback method as `callback(payload, schedule)`. The first argument is your payload, already parsed from JSON. The second is the schedule entry that triggered the call, typed as `Schedule<T>`, with `id`, `callback`, `type` (`"scheduled"`, `"delayed"` or `"cron"`), `time`, and `delayInSeconds` or `cron` where they apply.
One catch: as I remember the SDK, that second argument is the raw stored row. So its `payload` field may still be the JSON string, so use the first argument for the payload. Treat the second as metadata, for example to call `this.cancelSchedule(schedule.id)` or to see which kind of schedule fired. I'm answering from memory and didn't check it against the SDK source, so confirm with your installed version's types if it matters.Grade
wrong
The judge's reason: It says yes but then claims the second argument is the raw stored row with payload possibly a JSON string, which is the stale behavior presented as current.
Session log
Agent
Yes, assuming you mean the Cloudflare Agents SDK. When the alarm fires, the Agent calls your callback method as `callback(payload, schedule)`. The first argument is your payload, already parsed from JSON. The second is the schedule entry that triggered the call, typed as `Schedule<T>`, with `id`, `callback`, `type` (`"scheduled"`, `"delayed"` or `"cron"`), `time`, and `delayInSeconds` or `cron` where they apply. One catch: as I remember the SDK, that second argument is the raw stored row. So its `payload` field may still be the JSON string, so use the first argument for the payload. Treat the second as metadata, for example to call `this.cancelSchedule(schedule.id)` or to see which kind of schedule fired. I'm answering from memory and didn't check it against the SDK source, so confirm with your installed version's types if it matters.