跳到主内容
@wquguru
精选75Cloudflare Durable Objects(Changelog)云与平台

Durable Objects 新增 ctx.abort() 的 retryAlarm 选项

Durable Objects - Prevent Durable Object alarm retries when using `ctx.abort()`

原文
发到 X

By default, an alarm interrupted by ctx.abort() retries after the Durable Object resets. Pass { retryAlarm: false } when the alarm should stop instead:

默认情况下,被 ctx.abort() 中断的闹钟会在 Durable Object 重置后重试。若希望闹钟停止,请传入 { retryAlarm: false }:

src/index.jsjs

src/index.jsjs

代码 · 7
import { DurableObject } from "cloudflare:workers";
export class CleanupTask extends DurableObject {
	async alarm() {
		await this.ctx.storage.deleteAll();
		this.ctx.abort("Cleanup complete", { retryAlarm: false });
	}
}
代码 · 7
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

src/index.tsts

代码 · 7
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 });
	}
}
代码 · 7
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.

例如,一个删除其存储的闹钟可以使用此选项,以避免重复清理或重新运行 Durable Object 构造函数。

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.

闹钟可以与对同一 Durable Object 的其他请求并发运行。如果另一个请求在闹钟运行时调用 ctx.abort(),该调用上的 retryAlarm 选项也会控制闹钟是否重试。

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.

默认的重试行为可防止无关请求永久取消闹钟。应在每个应停止进行中闹钟的中断路径上设置 retryAlarm: false,而不仅仅是在闹钟处理程序中的调用。现有的 ctx.abort() 调用会继续重试闹钟。

For local development, retryAlarm requires Wrangler 4.126.0 or later.

对于本地开发,retryAlarm 需要 Wrangler 4.126.0 或更高版本。

For more information, refer to ctx.abort().

更多信息,请参阅 ctx.abort()。

更进一步:量化金融体系

看懂新闻只是起点——沿量化金融路径,把它变成能交付的工程能力

进入量化体系 →

相似阅读

另一事件,读法相近