Skip to main content

Run Checked

I ran into the struggle, that when running backups via cron I was never quite sure if they succeeded. Sure, I could rely on the cron error mails, but those are not generated when host is down entirely. On my journey to a solution I stumbled across a nice tool called Healthchecks.io. It does two things: Alerting when the cron job fails and when the corn job was not executed according to its schedule.

First, I tried wrapping my more complex backup scripts into bash scripts - monitoring the exit code of commands and piping stdout into a variable to maintain the log in Healthchecks. However, this proved to be quite difficult. Thus I wrote a small Python script to wrap my commands, gather stdout and stderr, and finally report everything back the my Healthchecks instance.

How to use

This is no ready-made script. It is rather intended to be used as a library, to provide quick utility functions.

from runchecked import HealthCheckedContext

with HealthCheckedContext(
    "...Your Healthchecks ping-back url here...",
    working_dir=".",  # Optionally set the general working directory
    enable_tty_output=None,  # Explicitly activate or deactive the echo to stdout. When left to None, it tries auto-detecting if the shell session is interactive
) as ctx:
    # Log some infos
    ctx.log.info("Backup started")

    # Set some environment variables global to the context
    ctx.set_env("Hello", "World")

    # Get the environment variable
    ctx.log.debug("Hello %s", ctx.get_env("Hello"))

    # Run some commands
    return_code = ctx.run(
      ["ls", "-alh", "."],  # commands are passed in the same way as in Python's `subprocess` library
      allow_fail=False,  # When true the context is not terminated, if the program exits with anything but 0
      timeout=None,  # Optional time for the program in seconds
      pass_env=True,  # If False only the system environment variables are passed, but not the context ones
    )

License

MIT License (c) Martin Peters aka FreakyBytes

Metadata

Release files for runchecked 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for runchecked 0.1.1
File Size Uploaded Provenance Actions
runchecked-0.1.1.tar.gz 4.0 kB Without provenance Details for runchecked-0.1.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for runchecked 0.1.1
File Interpreter ABI Platform Actions
runchecked-0.1.1-py3-none-any.whl Python 3 none any Details for runchecked-0.1.1-py3-none-any.whl

Total release size: 9.3 kB

Release files / runchecked-0.1.1.tar.gz

Download URL runchecked-0.1.1.tar.gz
Size 4.0 kB
Tags Source
SHA-256 checksum
How to use checksums
45a145b44a8a264d03c235377af8264405b894cd83944f7d699ffeea7f904c46
BLAKE2b-256 checksum
How to use checksums
132d242fca10896d22849016c23fa3a5e6599561edcd3fff7686a6f7f6139b93
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.4.2 requests/2.23.0 setuptools/44.0.0 requests-toolbelt/0.8.0 tqdm/4.43.0 CPython/3.7.7

Release files / runchecked-0.1.1-py3-none-any.whl

Download URL runchecked-0.1.1-py3-none-any.whl
Size 5.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1893632f4fcb0e43c01f7892efa1948621f61acaefcb15990efcb41d5942ca54
BLAKE2b-256 checksum
How to use checksums
439c4d74d270282590e497c12490a744bbfed23ac3ea685e93430db9a0bb8efa
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.4.2 requests/2.23.0 setuptools/44.0.0 requests-toolbelt/0.8.0 tqdm/4.43.0 CPython/3.7.7

Security for runchecked 0.1.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page