Skip to main content

Official Python SDK for CronSafe cron job monitoring

Project description

CronSafe Python SDK

Official Python SDK for CronSafe cron job monitoring.

Install

pip install cronsafe

Quick Start

from cronsafe import CronSafe

cs = CronSafe()

# Simple ping after your job completes
cs.ping("my-monitor-id")

# Track duration (start before, ping after)
cs.start("my-monitor-id")
run_backup()
cs.ping("my-monitor-id")

# Report failure with output
cs.fail("my-monitor-id", output="disk full")

# Context manager (recommended)
with cs.monitor("my-monitor-id"):
    run_backup()
    # Automatically sends /start, then /ping on success or /fail on error

Usage

Simple ping

Send a heartbeat after your job completes. If CronSafe does not receive the ping within the expected window, it fires an alert.

from cronsafe import CronSafe

cs = CronSafe()
cs.ping("nightly-backup")

Duration tracking

Send a /start ping before your job and a /ping after. CronSafe measures the time between them.

cs.start("nightly-backup")
run_backup()
cs.ping("nightly-backup")

Explicit failure

Report a failure immediately instead of waiting for a missed deadline. Include an optional output message that appears in your alert.

try:
    run_backup()
    cs.ping("nightly-backup")
except Exception as e:
    cs.fail("nightly-backup", output=str(e))
    raise

Context manager

The recommended way to monitor a job. Sends /start before the block, /ping on success, and /fail with the exception message on error.

with cs.monitor("nightly-backup"):
    run_backup()

Wrap a function

Same as the context manager but for a callable.

result = cs.wrap("nightly-backup", run_backup, arg1, arg2)

Custom API URL

cs = CronSafe(base_url="https://your-self-hosted-instance.com")

API key (optional)

cs = CronSafe(api_key="your-api-key")

API Reference

Method Description
ping(monitor_id) Heartbeat ping. Send after job completes.
start(monitor_id) Start a timed run. Send before job starts.
fail(monitor_id, output=None) Report failure. Alert fires immediately.
wrap(monitor_id, func, *args, **kwargs) Run a function with automatic monitoring.
monitor(monitor_id) Context manager for automatic monitoring.

Full documentation at getcronsafe.com/docs.

Links

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cronsafe-1.0.0.tar.gz (3.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

cronsafe-1.0.0-py3-none-any.whl (3.4 kB view details)

Uploaded Python 3

File details

Details for the file cronsafe-1.0.0.tar.gz.

File metadata

  • Download URL: cronsafe-1.0.0.tar.gz
  • Upload date:
  • Size: 3.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.10

File hashes

Hashes for cronsafe-1.0.0.tar.gz
Algorithm Hash digest
SHA256 76575ba4851e83a5518d35264a8b0cdd6627b17a9b52d12562306ffead64232a
MD5 9122a154126b2a80baf8c09bb04d2073
BLAKE2b-256 3223221ceb650d26138fced55f9e899a37ee7d3a2a3ec04bfe8f414464152cf2

See more details on using hashes here.

File details

Details for the file cronsafe-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: cronsafe-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 3.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.10

File hashes

Hashes for cronsafe-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c72a3e7c165952c758471dfafb488dc20048e14b7082b2ced0da38b561fc6eab
MD5 6ef17d7317a4ccc22144d703269ee017
BLAKE2b-256 473803f68f91f449dcdbd7a114b54228a4f9ed68b33e3598f214258838cabdca

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page