Cronping

Python

Ping Cronping from Python scripts.

Python's built-in urllib module is all you need — no external dependencies required.

Using urllib (no dependencies)

import urllib.request

def ping_cronping(token: str) -> None:
    url = f"https://ping.cronping.com/{token}"
    try:
        with urllib.request.urlopen(url, timeout=10) as response:
            response.read()
    except Exception as e:
        # Log the error but don't raise — the job succeeded
        print(f"Cronping notification failed: {e}", flush=True)

# Your job logic
def run_backup():
    # ... your code here ...
    pass

if __name__ == "__main__":
    run_backup()
    ping_cronping("<token>")

Using requests library

If you already use the requests library:

import requests

PING_URL = "https://ping.cronping.com/<token>"

def ping_cronping():
    try:
        requests.get(PING_URL, timeout=10)
    except requests.RequestException as e:
        print(f"Cronping notification failed: {e}")

# Your job
def main():
    # ... run your job ...
    pass

if __name__ == "__main__":
    main()
    ping_cronping()

As a decorator

For a clean integration with any function:

import urllib.request
import functools
import logging

logger = logging.getLogger(__name__)

def monitored(token: str):
    """Decorator that pings Cronping after the function succeeds."""
    def decorator(func):
        @functools.wraps(func)
        def wrapper(*args, **kwargs):
            result = func(*args, **kwargs)  # raises on failure
            try:
                url = f"https://ping.cronping.com/{token}"
                urllib.request.urlopen(url, timeout=10).read()
            except Exception as e:
                logger.warning("Cronping ping failed: %s", e)
            return result
        return wrapper
    return decorator


@monitored("<token>")
def run_daily_backup():
    # ... your backup logic ...
    pass

Start, fail, and exit code signals

import urllib.request
import subprocess

PING_URL = "https://ping.cronping.com/<token>"

def ping(suffix: str = "") -> None:
    try:
        urllib.request.urlopen(f"{PING_URL}/{suffix}".rstrip("/"), timeout=10).read()
    except Exception:
        pass  # Don't fail the job if the ping fails

# Signal start, run the job, then report the exit code
ping("start")
result = subprocess.run(["/usr/bin/backup.sh"])
ping(str(result.returncode))

Or explicitly signal failure:

ping("start")
try:
    run_backup()
    ping()  # success
except Exception:
    ping("fail")  # immediate Down alert
    raise

Scheduled with APScheduler

from apscheduler.schedulers.blocking import BlockingScheduler
import urllib.request

PING_URL = "https://ping.cronping.com/<token>"

def my_job():
    # ... your job logic ...

    # Ping Cronping on completion
    try:
        urllib.request.urlopen(PING_URL, timeout=10).read()
    except Exception as e:
        print(f"Ping failed: {e}")

scheduler = BlockingScheduler()
scheduler.add_job(my_job, "cron", hour=3, minute=0)
scheduler.start()

Django management command

# management/commands/my_task.py
from django.core.management.base import BaseCommand
import urllib.request

class Command(BaseCommand):
    help = "Run my scheduled task"

    def handle(self, *args, **options):
        # ... run the task ...

        # Ping Cronping
        try:
            urllib.request.urlopen(
                "https://ping.cronping.com/<token>",
                timeout=10
            ).read()
            self.stdout.write("Cronping notified")
        except Exception as e:
            self.stderr.write(f"Cronping ping failed: {e}")

On this page