-
Notifications
You must be signed in to change notification settings - Fork 136
chore: simplify debug logging for app readiness checks #520
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
7 commits
Select commit
Hold shift + click to select a range
086036b
chore: simplify debug logging for app readiness checks
DiscreteTom 95e6b3b
chore: print debug log if app is not ready for more than 5 seconds
DiscreteTom bda9b93
chore: reduce web readiness check interval from 5 to 2 seconds
DiscreteTom d59172c
chore: enhance debug logging for app readiness checks with URL context
DiscreteTom 50c471e
chore: change debug log level to info for app readiness checks
DiscreteTom 9c5e1e6
Merge branch 'main' into improve-logging
DiscreteTom 50fbc74
chore: extract Checkpoint struct for readiness check
DiscreteTom 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
use std::time::Instant; | ||
|
||
pub(crate) struct Checkpoint { | ||
start: Instant, | ||
interval_ms: u128, | ||
next_ms: u128, | ||
} | ||
|
||
impl Checkpoint { | ||
pub fn new() -> Checkpoint { | ||
// The default function timeout is 3 seconds. This will alert the users. See #520 | ||
let interval_ms = 2000; | ||
|
||
let start = Instant::now(); | ||
Checkpoint { | ||
start, | ||
interval_ms, | ||
next_ms: start.elapsed().as_millis() + interval_ms, | ||
} | ||
} | ||
|
||
pub const fn next_ms(&self) -> u128 { | ||
self.next_ms | ||
} | ||
|
||
pub const fn increment(&mut self) { | ||
self.next_ms += self.interval_ms; | ||
} | ||
|
||
pub fn lapsed(&self) -> bool { | ||
self.start.elapsed().as_millis() >= self.next_ms | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use super::*; | ||
|
||
#[test] | ||
fn test_checkpoint_new() { | ||
let checkpoint = Checkpoint::new(); | ||
assert_eq!(checkpoint.next_ms(), 2000); | ||
assert!(!checkpoint.lapsed()); | ||
} | ||
|
||
#[test] | ||
fn test_checkpoint_increment() { | ||
let mut checkpoint = Checkpoint::new(); | ||
checkpoint.increment(); | ||
assert_eq!(checkpoint.next_ms(), 4000); | ||
assert!(!checkpoint.lapsed()); | ||
} | ||
|
||
#[test] | ||
fn test_checkpoint_lapsed() { | ||
let checkpoint = Checkpoint { | ||
start: Instant::now(), | ||
interval_ms: 0, | ||
next_ms: 0, | ||
}; | ||
assert!(checkpoint.lapsed()); | ||
} | ||
} |
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.
Uh oh!
There was an error while loading. Please reload this page.