Skip to content

Instantly share code, notes, and snippets.

@nickw444
Last active March 17, 2020 10:49
Show Gist options
  • Select an option

  • Save nickw444/571383c5bfd98cbc1c5ced4f70ac8705 to your computer and use it in GitHub Desktop.

Select an option

Save nickw444/571383c5bfd98cbc1c5ced4f70ac8705 to your computer and use it in GitHub Desktop.
healthchecks.io long running job notifier
#!/usr/bin/env python3
import sys
import urllib.request
import subprocess
def main():
if len(sys.argv) < 3:
print("Usage: hc.py hc_url cmd [...cmd]")
sys.exit(1)
healthcheck_url = sys.argv[1]
cmd = sys.argv[2:]
urllib.request.urlopen(f"{healthcheck_url}/start")
result = subprocess.run(args=cmd)
if result.returncode == 0:
# Notify success
urllib.request.urlopen(f"{healthcheck_url}")
else:
# Notify failure
urllib.request.urlopen(f"{healthcheck_url}/fail")
# Exit with child return code
sys.exit(result.returncode)
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment