Monitoring python Intermediate New

Cron Job Heartbeat Monitor

Send a heartbeat ping after each cron job run — alert if a heartbeat is missed.

python
import httpx, os, functools, time

HEARTBEAT_URL = os.environ["HEARTBEAT_URL"]  # e.g. https://updown.io/api/checks/TOKEN/metrics

def with_heartbeat(fn):
    @functools.wraps(fn)
    def wrapper(*args, **kwargs):
        start = time.time()
        try:
            result = fn(*args, **kwargs)
            httpx.get(HEARTBEAT_URL, timeout=5)
            return result
        except Exception as e:
            httpx.get(HEARTBEAT_URL + "/fail", timeout=5)
            raise
    return wrapper

@with_heartbeat
def nightly_export():
    print("Running export...")

Prerequisites

  • httpx
  • Healthchecks.io or similar

Pro Tips

  • → Use healthchecks.io free tier for up to 20 monitors.

Was this module useful?

Share your experience — it helps the team improve.

Leave Feedback

Commercial Licensing

Acquire a production access token or template license for enterprise deployment.

Module Info

Language
python
Level
Intermediate
Read time
3 min
Published
Sep 2026
License
Commercial License

Newsletter

New modules every week, directly to your inbox.