import requests
URL = "{{ ping_url }}"

def do_work():
    # Do your number crunching, backup dumping, newsletter sending work here.
    # Return a truthy value on success.
    # Return a falsy value or throw an exception on failure.
    return True

success = False
try:
    success = do_work()
finally:
    # On success, requests {{ ping_url }}
    # On failure, requests {{ ping_url }}/fail
    requests.get(URL if success else URL + "/fail")