GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - main/sandy: Golang library for notifications about slow code execution

BranchesTags
Open more actions menu

Latest commit

 

History

12 Commits
12 Commits

Folders and files

NameName
Last commit message
Last commit date
app
app
 
 
mailer
mailer
 
 
watch_dog
watch_dog
 
 
.gitignore
.gitignore
 
 
LICENSE
LICENSE
 
 
README.md
README.md
 
 
go.mod
go.mod
 
 
go.sum
go.sum
 
 

Repository files navigation

sandy

A small Go watchdog library that emails you when your code runs slower than expected.

Wrap a long-running operation with OperationStarted / OperationFinished, and sandy will send a notification (via SendGrid) if:

  • MaxOperationTime is exceeded — the operation is taking too long overall;
  • MaxSilenceTime is exceeded — the operation hasn't reported progress for too long.

Useful for background workers and batch jobs where a hang would otherwise go unnoticed.

Install

go get github.com/main/sandy

Usage

package main

import (
	"context"
	"time"

	sandy "github.com/main/sandy/app"
	"github.com/main/sandy/mailer"
)

func main() {
	snd := sandy.New(context.Background(), sandy.Options{
		MaxSilenceTime:   5 * time.Second,
		MaxOperationTime: 2 * time.Second,
		MailerOptions: mailer.Options{
			InstanceName: "photo-worker",
			TemplateEmailSilenceMaxTimeExceeded: `
				Instance has reached the maximum silence timeout.
				Photos in progress: {{.NumberOfPhotos}}`,
			TemplateEmailOperationMaxTimeExceeded: `
				Instance has reached the maximum operation timeout.
				Photos in progress: {{.NumberOfPhotos}}`,
			SenderEmail: "[email protected]",
			SenderName:  "Sandy",
			Receivers:   []string{"[email protected]"},
			SendGridKey: "<your SendGrid API key>",
		},
	})

	// template arguments are rendered into the email body
	args := map[string]interface{}{"NumberOfPhotos": "213"}

	snd.OperationStarted(args)

	// ... do the work ...

	snd.OperationFinished()
}

Email templates use Go's text/template syntax; the arguments passed to OperationStarted are available inside the templates.

How it works

OperationStarted launches two watchdog timers (see watch_dog). If either timer fires before OperationFinished cancels them, the corresponding email is sent through the mailer package. Cancelling the parent context stops the watchdogs as well.

License

MIT — see LICENSE.

About

Golang library for notifications about slow code execution

Resources

Readme
MIT license
Activity

Stars

0 stars

Watchers

1 watching

Forks

0 forks
Report repository

Releases

Packages

Used by

Contributors

Languages

You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.