watchdog

package
v0.0.0-...-137c36e Latest Latest
Warning

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

Go to latest
Published: Dec 10, 2022 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Heartbeat

type Heartbeat interface {
	StillRunning(ctx context.Context)
}

type Instance

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

func NewWatchDog

func NewWatchDog(ctx context.Context, maxRunTime time.Duration) (*Instance, context.Context)

NewWatchDog creates a new watchdog Instance. Watchdog will call the cancel function associated with the returned context when maxRunTime has been exceeded. Pass the context returned to a long-running tasks that can be interrupted by a cancelled context.

Cancel() should be called on the returned Instance when you are done, or it will not be garbage collected until maxRunTime expires.

I'm using watchdog to time limit background tasks running in golang on an IoT sensor. The Heartbeat callback is used to reset (in)visibility of the task in a queue, so it is not dispatched to another sensor. Could also be used for long-running tasks driven by an AWS SQS queue for example.

func NewWatchDogWithHeartbeat

func NewWatchDogWithHeartbeat(ctx context.Context, maxRunTime time.Duration, heartbeat Heartbeat, heartbeatInterval time.Duration) (*Instance, context.Context)

NewWatchDogWithHeartbeat creates a new watch dog same NewWatchDog except in addition a callback is called every heartbeatInterval. Cancel() should be called when you are done with the instance, or it will run until maxRunTime expires.

func (*Instance) Cancel

func (i *Instance) Cancel()

Jump to

Keyboard shortcuts

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