Example #1
0
def is_backstop(params,
                push_interval=BACKSTOP_PUSH_INTERVAL,
                time_interval=BACKSTOP_TIME_INTERVAL):
    """Determines whether the given parameters represent a backstop push.

    Args:
        push_interval (int): Number of pushes
        time_interval (int): Minutes between forced schedules.
                             Use 0 to disable.
    Returns:
        bool: True if this is a backtop, otherwise False.
    """
    # In case this is being faked on try.
    if params.get("backstop", False):
        return True

    project = params["project"]
    pushid = int(params["pushlog_id"])
    pushdate = int(params["pushdate"])

    if project == "try":
        return False
    elif project != "autoland":
        return True

    # On every Nth push, want to run all tasks.
    if pushid % push_interval == 0:
        return True

    if time_interval <= 0:
        return False

    # We also want to ensure we run all tasks at least once per N minutes.
    index = BACKSTOP_INDEX.format(project=project)

    try:
        last_backstop_id = find_task_id(index)
    except KeyError:
        # Index wasn't found, implying there hasn't been a backstop push yet.
        return True

    if status_task(last_backstop_id) in ("failed", "exception"):
        # If the last backstop failed its decision task, make this a backstop.
        return True

    try:
        last_pushdate = get_artifact(last_backstop_id,
                                     "public/parameters.yml")["pushdate"]
    except HTTPError as e:
        # If the last backstop decision task exists in the index, but
        # parameters.yml isn't available yet, it means the decision task is
        # still running. If that's the case, we can be pretty sure the time
        # component will not cause a backstop, so just return False.
        if e.response.status_code == 404:
            return False
        raise

    if (pushdate - last_pushdate) / 60 >= time_interval:
        return True
    return False
Example #2
0
def _rerun_task(task_id, label):
    status = taskcluster.status_task(task_id)
    if status not in RERUN_STATES:
        logger.warning("No need to rerun {}: state '{}' not in {}!".format(
            label, status, RERUN_STATES))
        return
    taskcluster.rerun_task(task_id)
    logger.info("Reran {}".format(label))
Example #3
0
    def should_replace_task(self, task, params, index_paths):
        "Look for a task with one of the given index paths"
        for index_path in index_paths:
            try:
                task_id = find_task_id(index_path)
                status = status_task(task_id)
                if status not in ("exception", "failed"):
                    return task_id
            except KeyError:
                # 404 will end up here and go on to the next index path
                pass

        return False
Example #4
0
def rerun_action(parameters, graph_config, input, task_group_id, task_id,
                 task):
    parameters = dict(parameters)
    decision_task_id, full_task_graph, label_to_taskid = fetch_graph_and_labels(
        parameters, graph_config)
    label = task['metadata']['name']
    if task_id not in label_to_taskid.values():
        logger.error(
            "Refusing to rerun {}: taskId {} not in decision task {} label_to_taskid!"
            .format(label, task_id, decision_task_id))

    status = status_task(task_id)
    if status not in RERUN_STATES:
        logger.error("Refusing to rerun {}: state {} not in {}!".format(
            label, status, RERUN_STATES))
        sys.exit(1)
    rerun_task(task_id)
    logger.info('Reran {}'.format(label))
Example #5
0
    def should_replace_task(self, task, params, deadline, index_paths):
        "Look for a task with one of the given index paths"
        for index_path in index_paths:
            try:
                task_id = find_task_id(index_path)
                status = status_task(task_id)
                if status.get("state") in ("exception", "failed"):
                    continue

                if deadline and datetime.strptime(
                    status["expires"], self.fmt
                ) < datetime.strptime(deadline, self.fmt):
                    continue

                return task_id
            except KeyError:
                # 404 will end up here and go on to the next index path
                pass

        return False