#!/usr/bin/python
#
# Fail at archiving most of the time.
#

import pscheduler
import random
import sys

random.seed()

json = pscheduler.json_load(exit_on_error=True)


if random.random() > json["data"].get("fail", 0.5):
    result = {
        "succeeded": True
        }
else:
    if random.random() < json["data"].get("retry", 0.5):
        result = {
            "succeeded": False,
            "error": "Induced random failure with retry",
            "retry": "PT10S"
            }
    else:
        result = {
            "succeeded": False,
            "error": "Induced random failure, not retrying",
            }

pscheduler.succeed_json(result)
