Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Instance ¶
type Instance struct {
// contains filtered or unexported fields
}
func NewWatchDog ¶
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.