summaryrefslogtreecommitdiff
path: root/buildscripts/task_generation/gen_task_validation.py
blob: 2103c840acb2bc3938babd52147a1115b09e3c5e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
"""Validation checks for generating tasks."""
import inject
from evergreen import EvergreenApi


class GenTaskValidationService:
    """A service for validation around generating tasks."""

    @inject.autoparams()
    def __init__(self, evg_api: EvergreenApi) -> None:
        """
        Initialize the service.

        :param evg_api: Evergreen API client.
        """
        self.evg_api = evg_api

    def should_task_be_generated(self, task_id: str) -> bool:
        """
        Determine if we should attempt to generate tasks.

        If an evergreen task that calls 'generate.tasks' is restarted, the 'generate.tasks' command
        will no-op. So, if we are in that state, we should avoid generating new configuration files
        that will just be confusing to the user (since that would not be used).

        :param task_id: Id of the task being run.
        :return: Boolean of whether to generate tasks.
        """
        task = self.evg_api.task_by_id(task_id, fetch_all_executions=True)
        # If any previous execution was successful, do not generate more tasks.
        for i in range(task.execution):
            task_execution = task.get_execution(i)
            if task_execution.is_success():
                return False

        return True