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

[FEATURE] Add time span window for service start #132

Open
nickeskov opened this issue Nov 21, 2022 · 0 comments
Open

[FEATURE] Add time span window for service start #132

nickeskov opened this issue Nov 21, 2022 · 0 comments
Labels
enhancement New feature or request

Comments

@nickeskov
Copy link
Member

nickeskov commented Nov 21, 2022

Аbstract
Nodemon should have an option which can control time span window for service start.

Motivation and Purposes
For now nodemon starts instantly though network may be in inconsistent state which can lead to monitoring false positive alerts and warnings.

Specification
The main idea is to delay service start till, for example, 80% of provided scraping timeout. time.Now() should be rounded up to scraping timeout and then subbed by time.Now(). If the result is lower than, for example 0.8 * scrapingTimeout , then we should delay service start till 0.8 * scrapingTimeout - result.

Backwards Compatibility
Nope, the changing is fully compatible.

Examples and Implementation

var interval time.Duration
flag.DurationVar(&interval, "interval", 60*time.Second, "Polling interval, seconds. Default value is 60")
flag.Parse()
ctx, done := signal.NotifyContext(context.Background(), os.Interrupt)
defer done()
var (
	now                 = time.Now()
	windowUpperBoundary = interval
	windowLowerBoundary = interval * 4 / 5
)
if spanPoint := now.Truncate(windowUpperBoundary).Add(windowUpperBoundary).Sub(now); spanPoint < windowLowerBoundary {
	delayTime := windowLowerBoundary - spanPoint
	select {
	case <-time.After(delayTime):
	case <-ctx.Done():
		return nil
	}
}
@nickeskov nickeskov added the enhancement New feature or request label Nov 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant