Beispiel #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 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")
Beispiel #2
0
    def create_historic_task_entry(self, task_data):
        """
        Create a historic task entry

        Required task_data params:
            - task_label
            - task_success
            - start_time
            - finish_time
            - processed_by_worker

        :param task_data:
        :return:
        """
        if not task_data:
            self._log('Task data param empty',
                      json.dumps(task_data),
                      level="debug")
            raise Exception(
                'Task data param empty. This should not happen - Something has gone really wrong.'
            )

        new_historic_task = HistoricTasks.create(
            task_label=task_data['task_label'],
            task_success=task_data['task_success'],
            start_time=task_data['start_time'],
            finish_time=task_data['finish_time'],
            processed_by_worker=task_data['processed_by_worker'])
        return new_historic_task
Beispiel #3
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")
Beispiel #4
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()
Beispiel #5
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()
Beispiel #6
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()
Beispiel #7
0
    def get_historic_task_data_dictionary(self, task_id):
        """
        Read all data for a task and return a dictionary of that data

        :return:
        """
        # Get historic task matching the id
        try:
            # Fetch the historic task (get() will raise DoesNotExist exception if no results are found)
            historic_tasks = HistoricTasks.get_by_id(task_id)
        except HistoricTasks.DoesNotExist:
            self._log(
                "Failed to retrieve historic task from database for id {}.".
                format(task_id),
                level="exception")
            return False
        # Get all saved data for this task and create dictionary of task data
        historic_task = historic_tasks.model_to_dict()
        # Return task data dictionary
        return historic_task
Beispiel #8
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()
Beispiel #9
0
 def get_total_historic_task_list_count(self):
     query = HistoricTasks.select().order_by(HistoricTasks.id.desc())
     return query.count()