Skip to content

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

@nickeskov

Description

@nickeskov

А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
	}
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions