Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Durable Objects] Adding info on alarmInfo parameter for alarm() #18591

Merged
merged 6 commits into from
Dec 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/content/changelogs/durable-objects.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,8 @@ entries:
Durable Objects [request billing](/durable-objects/platform/pricing/#billing-metrics) applies a 20:1 ratio for incoming WebSocket messages. For example, 1 million Websocket received messages across connections would be charged as 50,000 Durable Objects requests.

This is a billing-only calculation and does not impact Durable Objects [metrics and analytics](/durable-objects/observability/graphql-analytics/).

- publish_date: "2024-02-15"
title: Optional `alarmInfo` parameter for Durable Object Alarms
description: |-
Durable Objects [Alarms](/durable-objects/api/alarms/) now have a new `alarmInfo` argument that provides more details about an alarm invocation, including the `retryCount` and `isRetry` to signal if the alarm was retried.
18 changes: 17 additions & 1 deletion src/content/docs/durable-objects/api/alarms.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,14 @@ Alarms can be used to build distributed primitives, like queues or batching of w

### `alarm`

- `alarm()`: <Type text='void' />
- <code>alarm(`alarmInfo`<Type text="Object"/>)</code>`: <Type text='void' />

- Called by the system when a scheduled alarm time is reached.

- The optional parameter `alarmInfo` object has two properties:
- `retryCount` <Type text="number"/>: The number of times this alarm event has been retried.
- `isRetry` <Type text="boolean"/>: A boolean value to indicate if the alarm has been retried. This value is `true` if this alarm event is a retry.

- The `alarm()` handler has guaranteed at-least-once execution and will be retried upon failure using exponential backoff, starting at 2 second delays for up to 6 retries. Retries will be performed if the method fails with an uncaught exception.

- This method can be `async`.
Expand Down Expand Up @@ -102,6 +106,18 @@ export class AlarmExample extends DurableObject {
}
```

The following example shows how to use the `alarmInfo` property to identify if the alarm event has been attempted before.

```js
class MyDurableObject extends DurableObject {
async alarm(alarmInfo) {
if (alarmInfo?.retryCount != 0) {
console.log("This alarm event has been attempted ${alarmInfo?.retryCount} times before.");
}
}
}
```

## Related resources

- Understand how to [use the Alarms API](/durable-objects/examples/alarms-api/) in an end-to-end example.
Expand Down
6 changes: 5 additions & 1 deletion src/content/docs/durable-objects/api/base.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,14 @@ export class MyDurableObject extends DurableObject {

### `alarm`

- <code>alarm()</code>: <Type text="Promise <void>"/>
- <code>alarm(`alarmInfo`<Type text="Object"/>)</code>: <Type text="Promise <void>"/>

- Called by the system when a scheduled alarm time is reached.

- The optional parameter `alarmInfo` object has two properties:
- `retryCount` <Type text="number"/>: The number of times this alarm event has been retried.
- `isRetry` <Type text="boolean"/>: A boolean value to indicate if the alarm has been retried. This value is `true` if this alarm event is a retry.

- The `alarm()` handler has guaranteed at-least-once execution and will be retried upon failure using exponential backoff, starting at two second delays for up to six retries. Retries will be performed if the method fails with an uncaught exception.

- This method can be `async`.
Expand Down
Loading