Skip to content

Watchdog will call the cancel function associated with the returned context when a max run time has been exceeded. Pass the context returned to a long-running tasks that can be interrupted by a cancelled context.

License

Notifications You must be signed in to change notification settings

davidwartell/go-watchdog

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

go-watchdog

Watchdog will call the cancel function associated with the returned context when a max run time has been exceeded.
Pass the context returned to a long-running tasks that can be interrupted by a cancelled context.

Usage

Example

// create a new watchdog
watchDog, watchDogCtx := watchdog.NewWatchDog(
    ctx,
    time.Duration(300) * time.Second,
)
defer watchDog.Cancel()

// SomeLongRunningFunction that we want to run no more than 300 seconds.  Function should exit if watchDogCtx is cancelled.
// Use context aware network/database connections in this function.  If you have long running computations in a loop
// periodically check if watchDogCtx.Err() != nil in SomeLongRunningFunction.
SomeLongRunningFunction(watchDogCtx)

Contributing

Happy to accept PRs.

Author

davidwartell

About

Watchdog will call the cancel function associated with the returned context when a max run time has been exceeded. Pass the context returned to a long-running tasks that can be interrupted by a cancelled context.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages