Monitor Flask-APScheduler Jobs with CronRabbit
FlaskThe Problem
Flask-APScheduler runs tasks inside your Flask process. If the process restarts, the scheduler resets. If a task fails, there's no external notification.
The Solution
Add CronRabbit pings inside your APScheduler job functions. Each job gets a monitor for independent alerting.
Integration
Import requests and add pings at the start and end of each scheduled function. APScheduler handles the schedule; CronRabbit verifies execution.
Code Examples
Flask-APScheduler with monitoring
Pythonfrom flask import Flask
from flask_apscheduler import APScheduler
import requests
app = Flask(__name__)
scheduler = APScheduler()
PING = "https://ping.cronrabbit.com/your-id"
@scheduler.task("cron", id="cleanup", hour=2)
def nightly_cleanup():
requests.get(f"{PING}/start", timeout=5)
try:
cleanup_expired_data()
requests.get(PING, timeout=5)
except Exception:
requests.get(f"{PING}/fail", timeout=5)
raise
scheduler.init_app(app)
scheduler.start()