Hey Lambros, was wondering if the team got back to you on this > Regarding the behavior of setting

Hey Lambros, was wondering if the team got back to you on this

Regarding the behavior of setting an alarm and throwing right after, I will check with the team and get back to you.

Providing a more fleshed out example to better-communicate what I'm asking - hopefully it makes sense

export class MyDurableObject {
    constructor(state, env) {
        this.state = state;
        this.env = env;
    }

    async alarm() {
        console.log("Alarm triggered");

        // Will this alarm be set? or would it be "overriden" by the retry of the original alarm
        await this.state.storage.setAlarm(Date.now() + 150000);

        // Call a method that fails
        await this.failingMethod(); // failure
    }

    async fetch(request) {
        const url = new URL(request.url);

        if (url.pathname === "/start") {
            console.log("Starting recursive alarm loop...");
            await this.state.storage.setAlarm(Date.now() + 5000);
            return new Response("Alarm scheduled.");
        }

        return new Response("Unknown command", { status: 400 });
    }

    async failingMethod() {
        throw new Error("Intentional failure to demonstrate failure handling");
    }
}
Was this page helpful?