コード例 #1
0
    def get_tasks(self, repo_dir: str = None, task_state: TaskState = None) -> List[Task]:
        """ Gets a list of tasks.

        Args:
            session (Session): The database session.
            repo_dir (str, optional): The task repository. Defaults to None.
            task_state (TaskState, optional): The task state. Defaults to None.

        Returns:
            List[Task]: List of tasks.
        """
        session: Schema = self.get_schema()
        return Tasks.get_tasks(session, repo_dir, task_state)
コード例 #2
0
    def update_task_state(self, task_id: int, task_state: TaskState) -> None:
        """ Updates the state of a task.

        Args:
            task_id (str): The task id.
            task_state (TaskState): The task state.

        Raises:
            ValueError:
                Thrown when missing task_id or task_state.
        """
        if task_id is None or task_state is None:
            raise ValueError(
                "You cannot get the update the state of a task "
                "without a task_id and a task_state.")
        session: Schema = self.get_schema()
        return Tasks.update_task_state(session, task_id, task_state)
コード例 #3
0
    def get_task(self, task_id: int) -> Task:
        """ Gets the task record with that task_id.

        Args:
            session (Session): The database session.
            task_id (int): The task id.

        Raises:
            ValueError: Thrown when missing task_id.

        Returns:
            Task: The task.
        """
        if task_id is None:
            raise ValueError("You cannot get a task without a task_id.")
        session: Schema = self.get_schema()
        return Tasks.get_task(session, task_id)
コード例 #4
0
    def update_task_type(self, task_id: int, task_type: TaskType, params: dict = None) -> None:
        """ Updates the type of a task and his parameters if needed.

        Args:
            task_id (str): The task id.
            task_type (int): The task type.
            params (str, optional): The task parameters.

        Raises:
            ValueError:
                Thrown when missing task_id or task_type.
        """
        if task_id is None or task_type is None:
            raise ValueError(
                "You cannot get the update the type of a task "
                "without a task_id and a task_type.")
        session: Schema = self.get_schema()
        return Tasks.update_task_type(session, task_id, task_type, params)
コード例 #5
0
    def get_oldest_task_with_state(self, task_type: TaskType, task_state: TaskState) -> Task:
        """ Gets the oldest queued task record.

        Args:
            task_type (TaskType): The task type.
            task_state (TaskState): The task state.

        Raises:
            ValueError:
                Thrown when missing task_type or task_state.

        Returns:
            Task: The oldest queued task with that type and state.
        """
        if task_type is None or task_state is None:
            raise ValueError(
                "You cannot get the oldest task without a task_type and a task_state.")
        session: Schema = self.get_schema()
        return Tasks.get_oldest_task_with_state(session, task_type, task_state)
コード例 #6
0
    def create_task(self, repo_dir: str, task_type: TaskType, params: dict = None) -> Task:
        """ Creates a new task.

        Args:
            repo_dir (str): The task repository.
            task_type (TaskType): The task type.

        Raises:
            ValueError: Thrown when missing repo_dir.

        Returns:
            Task: The task.
        """
        if not repo_dir or task_type is None:
            raise ValueError(
                "You cannot create a task without a repo_dir and a task_type.")
        session: Schema = self.get_schema()
        return Tasks.create(
            session, TaskState.QUEUED, datetime.utcnow(), repo_dir, task_type, params)
コード例 #7
0
    def get_latest_task_from_repo(self,
                                  repo_dir: str,
                                  task_type: TaskType = None,
                                  task_state: TaskState = None) -> Task:
        """ Gets the latest task record with that repo_dir.

        Args:
            repo_dir (str): The task repository.
            task_type (TaskType, optional): The task type. Defaults to None.
            task_state (TaskState, optional): The task state. Defaults to None.

        Raises:
            ValueError:
                Thrown when missing repo_dir.

        Returns:
            List[Task]: List of tasks.
        """
        if not repo_dir:
            raise ValueError(
                "You cannot get the lastest task from an unknown repo_dir.")
        session: Schema = self.get_schema()
        return Tasks.get_latest_task_from_repo(session, repo_dir, task_type, task_state)