Python
requests, urllib, and a decorator that reports exceptions.
Requests
import requests
PING = "https://vivere.dev/p/<monitor-id>"
def ping(suffix="", body=None):
try:
requests.post(f"{PING}{suffix}", data=body, timeout=10)
except requests.RequestException:
pass # never let monitoring break the job
A decorator for scheduled functions
import functools, traceback
def monitored(func):
@functools.wraps(func)
def wrapper(*args, **kwargs):
ping("/start")
try:
result = func(*args, **kwargs)
except Exception:
ping("/fail", traceback.format_exc()[-16000:])
raise
ping("", f"{func.__name__} ok")
return result
return wrapper
@monitored
def nightly_etl():
...
Standard library only
import urllib.request
try:
urllib.request.urlopen("https://vivere.dev/p/<monitor-id>", timeout=10)
except Exception:
pass