Python
Standard library only (urllib). Works with any Python 3. On an error it sends the error and the last 20 lines of the traceback; the Failed alert and the job page show them. The example line (df = ...) runs as pasted: replace it with your own code.
The code
This is the code the Code tab generates (with start, errors and rows ticked). In the app it already contains your job's own address.
# --- TaskBeacon: top of the script (standard library only) ---
import json, traceback, urllib.request
TB = "https://taskbeacon.io/ping/your-job-id"
def tb_ping(path="", data=None):
body = json.dumps(data).encode() if data else None
req = urllib.request.Request(TB + path, data=body, headers={"Content-Type": "application/json"})
try:
urllib.request.urlopen(req, timeout=10)
except Exception as e:
print("TaskBeacon ping failed:", e)
tb_ping("/start")
try:
# --- your code here ---
df = [1, 2, 3] # example data: replace with your own (e.g. pandas.read_csv)
except Exception as e:
# the error and the last 20 lines of the traceback go with the failure
tb_ping("/fail", {"error": f"{type(e).__name__}: {e}"[:200],
"log": "\n".join(traceback.format_exc().splitlines()[-20:])[-4000:]})
raise
# --- TaskBeacon: end of the script ---
tb_ping("", {"rows": len(df)})How it works
The code pings /start when the script begins, the plain address with the row count when it ends well, and /fail when it fails, with the error and the last 20 lines of the traceback.
Untick options on the Code tab to leave parts out; untick Send output lines to send no output, only the error or exit code. See what can be reported.
Run a Python script on a schedule
On Windows, create a task from a Command Prompt. Use the full path of the Python you installed packages into (where python shows it), or of your virtual environment:
schtasks /Create /TN "Sales report" /SC DAILY /ST 06:00 /TR "C:\jobs\venv\Scripts\python.exe C:\jobs\sales.py"
On Linux or a Mac, one crontab line (crontab -e):
0 6 * * * /home/me/jobs/venv/bin/python /home/me/jobs/sales.py
Use python.exe, not pythonw.exe, if you want to see the output when you start the task by hand.
Why the exit code isn't enough
An uncaught exception makes Python exit with code 1, so the scheduler sees that kind of failure. It does not see the quiet ones: an empty query result, an API that answered with no data, a try/except that logs and carries on, or a run that never started because the machine was off.
The code above sends /fail with the error message and the last 20 lines of the traceback, and then re-raises, so the exit code stays honest; a run that never starts shows as Missed.
Report the row count
The last line sends len(df). Replace df with your result (a pandas DataFrame, a list of rows, the number your insert returned). More numbers go in the same JSON:
tb_ping("", {"rows": len(df), "total": float(df["amount"].sum())})
The code uses only the standard library (urllib), so it works without requests.
Common problems
- ModuleNotFoundError under the scheduler only. The task runs another Python. Point the task at the venv's
python.exe. - Relative paths. They are relative to the task's Start in folder, not the script's. Build paths from
pathlib.Path(__file__).parent. - SSL: CERTIFICATE_VERIFY_FAILED. A company proxy that inspects HTTPS uses its own certificate; ask IT for it, or run the script with the Python your IT team provides.
- Network drives. A task that runs while you are logged out doesn't see mapped drive letters; use UNC paths.
Use cases: Get an alert when a Python cron job or scheduled script fails · Get an alert when an SPSS Statistics production job fails · Monitor a scheduled AI agent or LLM job · Get an alert when an AI job returns an empty or too-short answer · Get an alert when a job loads 0 rows, or far fewer than usual · Check that a daily table or file is fresh · Check that last night's backup exists and isn't empty. More questions: FAQ.