-
Notifications
You must be signed in to change notification settings - Fork 10.4k
[DO] Adding alarm limitation when working in local dev. #20000
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
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -31,3 +31,9 @@ For this reason, it is best practice to ensure that API changes between your Wor | |
| The Workers editor in the [Cloudflare dashboard](https://dash.cloudflare.com/) allows you to interactively edit and preview your Worker and Durable Objects. In the editor, Durable Objects can only be talked to by a preview request if the Worker being previewed both exports the Durable Object class and binds to it. Durable Objects exported by other Workers cannot be talked to in the editor preview. | ||
|
|
||
| [`wrangler dev`](/workers/wrangler/commands/#dev) has read access to Durable Object storage, but writes will be kept in memory and will not affect persistent data. However, if you specify the `script_name` explicitly in the [Durable Object binding](/workers/runtime-apis/bindings/), then writes will affect persistent data. Wrangler will emit a warning in that case. | ||
|
|
||
| ## Alarms in local Development | ||
|
|
||
| Currently, when developing locally (using `npx wrangler dev`), Durable Object [alarm methods](/durable-objects/api/alarms) may fail after a hot reload (if you edit the code while the code is running locally). | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @lambrospetrou I don't see this behavior where alarm methods work if no hot deploy. I'm not making code edits https://paste.cfdata.org/JQ6bKUqtiYtrTKY3sbMC is the Worker code im running
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I added some Works for both versions to me. If you set an alarm very in the future, maybe the local miniflare implementation doesn't work correctly once the DO hibernates?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
No, I figured out my code was incorrect. I was calling Which raises a different clarifying question: is the DO constructor always called when the alarm handler runs? I see this with Sample output: Our docs say: "Durable Objects alarms allow you to schedule the Durable Object to be woken up at a time in the future." I get that if your DO is inactive, then the alarm would start up the DO, ie run the constructor. But if your scheduled alarm time occurs when the DO is already running, then what happens (I assume the constructor is not invoked)?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Seems to be local-only behavior. With Workers Logs on my deployed Worker, I dont see the additional constructor calls. @Oxyjun worth documenting this behavior as well, assuming its expected cc @lambrospetrou @joshthoward ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🩷🩷🩷
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The constructor is called only when the DO cold starts. If an alarm is very far apart from the previous run and the DO hibernates inbetween then yes the constructor would run each time the alarm would run.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's not a problem to set an alarm within the constructor. I did that in my example case above too.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
So it's not determined by whether you're using local-only vs deploy remote?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No. Although the time until the DO hibernates locally vs remote could be different. I dont know the exact values.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for confirming. @vy-ton I think this PR is good to merge as far as "Known issues" are concerned, let me know if you're happy to merge :D |
||
|
|
||
| To avoid this issue, when using Durable Object alarms, close and restart your `wrangler dev` command after editing your code. | ||
Uh oh!
There was an error while loading. Please reload this page.