-
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
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The 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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added some
awaitas well since the alarm API is officially async: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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, I figured out my code was incorrect. I was calling
setAlarmin my constructor, forgetting that when the alarm is invoked the DO constructor is called.Which raises a different clarifying question: is the DO constructor always called when the alarm handler runs? I see this with
wrangler dev. Is it local miniflare only behavior?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)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The 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 comment
The reason will be displayed to describe this comment to others. Learn more.
🩷🩷🩷
There was a problem hiding this comment.
Choose a reason for hiding this comment
The 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.
But if the alarm is much more often, e.g. every second, then the constructor won't be running for every alarm.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The 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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The 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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The 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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The 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