monitor

package
v0.0.0-...-a3125ed Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 10, 2025 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package monitor implements a self-monitoring auto-restart mechanism.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsMonitored

func IsMonitored(envKey string) bool

IsMonitored returns true if current process is being monitored to restart automatically.

func SelfMonitor

func SelfMonitor(ctx context.Context, envKey string, opts *Options) error

SelfMonitor creates another instance of the current program and watches it to auto-restart on failures till the input context is expired. When the input context is expired, existing child process will be signaled to shutdown and the function returns a non-nil error.

The input `envKey` must be an application-specific, unique non-empty environment variable name, which is used internally to distinguish between the monitor instance and the monitored instance. A temporary http server URL is stored in the envKey value, which can optionally receive child processes' initialization status.

Types

type Options

type Options struct {
	ShutdownSignal    os.Signal     // Defaults to os.Interrupt
	ShutdownTimeout   time.Duration // Defaults to 10 seconds.
	MinBackoffTimeout time.Duration // Defaults to one second.
	MaxBackoffTimeout time.Duration // Defaults to one minute.
}

Options defines the user configurable values for the Monitor.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL