Last active
March 17, 2020 10:49
-
-
Save nickw444/571383c5bfd98cbc1c5ced4f70ac8705 to your computer and use it in GitHub Desktop.
healthchecks.io long running job notifier
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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