Пример #1
0
    def delete_historic_tasks_recursively(self, id_list=None):
        """
        Deletes a given list of historic tasks based on their IDs

        :param id_list:
        :return:
        """
        # Prevent running if no list of IDs was given
        if not id_list:
            return False

        try:
            query = (HistoricTasks.select())

            if id_list:
                query = query.where(HistoricTasks.id.in_(id_list))

            for historic_task_id in query:
                try:
                    historic_task_id.delete_instance(recursive=True)
                except Exception as e:
                    # Catch delete exceptions
                    self._log(
                        "An error occurred while deleting historic task ID: {}."
                        .format(historic_task_id),
                        str(e),
                        level="exception")
                    return False

            return True

        except HistoricTasks.DoesNotExist:
            # No historic entries exist yet
            self._log("No historic tasks exist yet.", level="warning")
Пример #2
0
    def delete_historic_tasks_recursively(self, id_list=None):
        """
        Deletes a given list of historic tasks based on their IDs

        :param id_list:
        :return:
        """
        # Prevent running if no list of IDs was given
        if not id_list:
            return False

        try:
            query = (HistoricTasks.select())

            if id_list:
                query = query.where(HistoricTasks.id.in_(id_list))

            for task_id in query:
                result = common.delete_model_recursively(task_id)
                if not result:
                    # break there and return
                    self._log("Failed to delete task ID: {}.".format(task_id),
                              level="warning")
                    return False

            return True

        except HistoricTasks.DoesNotExist:
            # No historic entries exist yet
            self._log("No historic tasks exist yet.", level="warning")
Пример #3
0
    def get_historic_task_list_filtered_and_sorted(self,
                                                   order=None,
                                                   start=0,
                                                   length=None,
                                                   search_value=None,
                                                   id_list=None):
        try:
            query = (HistoricTasks.select())

            if id_list:
                query = query.where(HistoricTasks.id.in_(id_list))

            if search_value:
                query = query.where(
                    HistoricTasks.task_label.contains(search_value))

            # Get order by
            if order:
                if order.get("dir") == "asc":
                    order_by = attrgetter(
                        order.get("column"))(HistoricTasks).asc()
                else:
                    order_by = attrgetter(
                        order.get("column"))(HistoricTasks).desc()

            if length:
                query = query.order_by(order_by).limit(length).offset(start)

        except HistoricTasks.DoesNotExist:
            # No historic entries exist yet
            self._log("No historic tasks exist yet.", level="warning")
            query = []

        return query.dicts()
Пример #4
0
    def get_historic_task_list(self, limit=None):
        """
        Read all historic tasks entries

        :return:
        """
        try:
            # Fetch a single row (get() will raise DoesNotExist exception if no results are found)
            if limit:
                historic_tasks = HistoricTasks.select().order_by(
                    HistoricTasks.id.desc()).limit(limit)
            else:
                historic_tasks = HistoricTasks.select().order_by(
                    HistoricTasks.id.desc())
        except HistoricTasks.DoesNotExist:
            # No historic entries exist yet
            self._log("No historic tasks exist yet.", level="warning")
            historic_tasks = []

        return historic_tasks.dicts()
Пример #5
0
    def get_historic_tasks_list_with_source_probe(self,
                                                  order=None,
                                                  start=0,
                                                  length=None,
                                                  search_value=None,
                                                  id_list=None,
                                                  task_success=None,
                                                  abspath=None):
        """
        Return a list of matching historic tasks with their source file's ffmpeg probe.

        :param order:
        :param start:
        :param length:
        :param search_value:
        :param id_list:
        :param task_success:
        :param abspath:
        :return:
        """
        query = (HistoricTasks.select(HistoricTasks.id,
                                      HistoricTasks.task_label,
                                      HistoricTasks.task_success,
                                      HistoricTaskProbe.type,
                                      HistoricTaskProbe.abspath))

        if id_list:
            query = query.where(HistoricTasks.id.in_(id_list))

        if search_value:
            query = query.where(
                HistoricTasks.task_label.contains(search_value))

        if task_success is not None:
            query = query.where(HistoricTasks.task_success.in_([task_success]))

        if abspath:
            query = query.where(HistoricTaskProbe.abspath.in_([abspath]))

        predicate = ((HistoricTaskProbe.historictask_id == HistoricTasks.id) &
                     (HistoricTaskProbe.type == "source"))

        query = query.join(HistoricTaskProbe, on=predicate)

        return query.dicts()
Пример #6
0
    def get_current_path_of_historic_tasks_by_id(self, id_list=None):
        """
        Returns a list of HistoricTasks filtered by id_list and joined with the current absolute path of that file.
        For failures this will be the the source path
        For success, this will be the destination path

        :param id_list:
        :return:
        """
        """
            SELECT
                t1.*,
                t2.type,
                t2.abspath
            FROM historictasks AS "t1"
            INNER JOIN "historictaskprobe" AS "t2"
                ON (
                    ("t2"."historictask_id" = "t1"."id" AND t1.task_success AND t2.type = "source")
                    OR
                    ("t2"."historictask_id" = "t1"."id" AND NOT t1.task_success AND t2.type = "destination")
                )
            WHERE t1.id IN ( %s)
        """
        query = (HistoricTasks.select(HistoricTasks.id,
                                      HistoricTasks.task_label,
                                      HistoricTasks.task_success,
                                      HistoricTaskProbe.type,
                                      HistoricTaskProbe.abspath))

        if id_list:
            query = query.where(HistoricTasks.id.in_(id_list))

        predicate = ((HistoricTaskProbe.historictask_id == HistoricTasks.id) &
                     (((HistoricTasks.task_success == True) &
                       (HistoricTaskProbe.type == "destination"))
                      | ((HistoricTasks.task_success != True) &
                         (HistoricTaskProbe.type == "source"))))

        query = query.join(HistoricTaskProbe, on=predicate)

        return query.dicts()
Пример #7
0
 def get_total_historic_task_list_count(self):
     query = HistoricTasks.select().order_by(HistoricTasks.id.desc())
     return query.count()