Monitor Go Cron Jobs

Learn how to monitor scheduled tasks in Go applications using robfig/cron or the standard library.

Features

  • Works with robfig/cron and standard library
  • Goroutine-safe monitoring
  • HTTP client with retries
  • Minimal dependencies

Code Examples

robfig/cron
package main

import (
    "net/http"
    "github.com/robfig/cron/v3"
)

func main() {
    c := cron.New()

    c.AddFunc("*/5 * * * *", func() {
        checkURL := "https://haspulse.io/ping/YOUR_CHECK_ID"

        // Signal start
        http.Get(checkURL + "/start")

        err := processQueue()
        if err != nil {
            http.Get(checkURL + "/fail")
            return
        }

        // Signal success
        http.Get(checkURL)
    })

    c.Start()
    select {}
}
Helper function
package monitor

import (
    "fmt"
    "net/http"
    "time"
)

var client = &http.Client{Timeout: 10 * time.Second}

func Ping(checkID string, status string) error {
    url := fmt.Sprintf("https://haspulse.io/ping/%s", checkID)
    if status != "" {
        url += "/" + status
    }

    resp, err := client.Get(url)
    if err != nil {
        return err
    }
    defer resp.Body.Close()
    return nil
}

// Usage:
// monitor.Ping("YOUR_CHECK_ID", "start")
// monitor.Ping("YOUR_CHECK_ID", "")      // success
// monitor.Ping("YOUR_CHECK_ID", "fail")

How It Works

  1. 1
    Create a check in Haspulse
    Set your expected schedule (e.g., every 5 minutes)
  2. 2
    Add the ping to your code
    Ping the unique URL when your job runs successfully
  3. 3
    Get alerted on failures
    If a ping doesn't arrive on time, we notify you

Related Integrations

Start monitoring in minutes

Create your first check and start receiving alerts when your scheduled jobs fail.

Get started free