health

package
v0.0.0-...-dd7c89d Latest Latest
Warning

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

Go to latest
Published: Jan 30, 2025 License: MIT Imports: 10 Imported by: 7

Documentation

Index

Constants

View Source
const CheckPath = "/soh"

CheckPath is the baked in SOH endpoint path.

Variables

This section is empty.

Functions

func Check

func Check(ctx context.Context, servicePath string, timeout time.Duration) ([]byte, error)

Check calls the given service endpoint with a given context and timeout. An error will be returned if the connection fails, or the response status is not 200 (i.e. StatusOK). A successful check will return only the check message reply.

func CheckStatus

func CheckStatus(servicePath string, timeout time.Duration) int

CheckStatus runs a Check on the given service and returns zero for a healthy service, and one otherwise.

@param {string} servicePat: service address and path to check e.g. 8080/soh

func RunningHealthCheck

func RunningHealthCheck() bool

RunningHealthCheck returns whether the -check flag was used when starting the program. This flag indicates that the program is being used to run a health check on another program.

Types

type Service

type Service struct {
	// contains filtered or unexported fields
}

Service provides a mechanism to update a service SOH status.

func New

func New(endpoint string, aged, startup time.Duration) *Service

New returns a health Service which provides running SOH capabilities.

func (*Service) Alive

func (s *Service) Alive(ctx context.Context, heartbeat time.Duration) context.CancelFunc

Alive allows an application to perform a complex task while still sending hearbeats.

func (*Service) Fail

func (s *Service) Fail()

Fail updates the Service to indicate the service is not running as expected.

func (*Service) Ok

func (s *Service) Ok()

Ok updates the Service to indicate the service is running as expected.

func (*Service) Pause

func (s *Service) Pause(ctx context.Context, deadline, heartbeat time.Duration) context.CancelFunc

Pause allows an application to stall for a set period of time while still sending hearbeats.

func (*Service) Update

func (s *Service) Update(status bool)

Update sets the Service to the given state, and stores the time since the last update.

Jump to

Keyboard shortcuts

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