Monitor Scheduled Tasks in Go Gin Applications

Gin

The Problem

Go Gin applications often run background goroutines for scheduled work. If these goroutines panic or hang, the web server keeps running but scheduled tasks stop.

The Solution

Use robfig/cron alongside Gin and add CronRabbit pings in each job function.

Pattern

Start the cron scheduler alongside your Gin server. Add monitoring pings inside each scheduled function.

Code Examples

Gin with cron monitoring

Go
package main

import (
	"github.com/gin-gonic/gin"
	"github.com/robfig/cron/v3"
	"net/http"
	"time"
)

func main() {
	client := &http.Client{Timeout: 10 * time.Second}
	c := cron.New()
	c.AddFunc("0 */6 * * *", func() {
		client.Get("https://ping.cronrabbit.com/your-id/start")
		if err := cleanupSessions(); err != nil {
			client.Get("https://ping.cronrabbit.com/your-id/fail")
			return
		}
		client.Get("https://ping.cronrabbit.com/your-id")
	})
	c.Start()

	r := gin.Default()
	r.Run(":8080")
}

Ready to Monitor Your Cron Jobs?

Create your free account and add your first monitor in under 5 minutes. No credit card required.