Angaben zum Datum
Datum aus der Quelle.
Erstmals gesehen am .
Storage von Cloudflare
Alarm-Wiederholung bei ctx.abort() in Durable Objects verhindern
Mit der Option { retryAlarm: false } bei ctx.abort() lässt sich verhindern, dass ein unterbrochener Alarm nach dem Zurücksetzen des Durable Objects erneut ausgeführt wird, während bestehende Aufrufe weiterhin Alarme wiederholen.
By default, an alarm interrupted by ctx.abort() retries after the Durable Object resets. Pass { retryAlarm: false } when the alarm should stop instead:
src/index.jsjs
import { DurableObject } from "cloudflare:workers";
export class CleanupTask extends DurableObject {
async alarm() {
await this.ctx.storage.deleteAll();
this.ctx.abort("Cleanup complete", { retryAlarm: false });
}
}
src/index.tsts
import { DurableObject } from "cloudflare:workers";
export class CleanupTask extends DurableObject {
async alarm(): Promise<void> {
await this.ctx.storage.deleteAll();
this.ctx.abort("Cleanup complete", { retryAlarm: false });
}
}
For example, an alarm that deletes its storage can use this option to avoid repeating the cleanup or re-running the Durable Object constructor.
Alarms can run concurrently with other requests to the same Durable Object. If another request calls ctx.abort() while an alarm is running, the retryAlarm option on that call also controls whether the alarm retries.
The default retry prevents an unrelated request from permanently canceling the alarm. Set retryAlarm: false on every abort path that should stop an in-progress alarm, not only on calls from the alarm handler. Existing calls to ctx.abort() keep retrying alarms.