Hmm, are you maybe setting the alarm to
Hmm, are you maybe setting the alarm to run in the constructor? Alternatively, are you calling the
alarm() handler directly somewhere in your DO code?alarm() handler anywherescheduleNextPost() anywhere else other than the alarm()?alarm method is overridden to be called in the constructor: https://github.com/cloudflare/agents/blob/main/packages/agents/src/index.ts#L319schedule method needs to be used instead. https://developers.cloudflare.com/agents/api-reference/schedule-tasks/
scheduleNextPost()alarmschedule private async scheduleNextPost() {
const randomHours = 2 + Math.floor(Math.random() * 7);
const milliseconds = randomHours * 60 * 60 * 1000;
await this.ctx.storage.setAlarm(Date.now() + milliseconds);
}
async alarm() {
await this.doSomething();
await this.scheduleNextPost();
}