Exemplo n.º 1
0
 def test_task_finished_queue(self):
     # Arrange
     task = Task(1, "", [""], None, "", "")
     task.job_id = 1234
     task.message_type = TaskMessageType.TASK_PROCESSED
     connected_task = ConnectedTask(task, "")
     self.task_manager.in_progress[task.task_id] = connected_task
     # Act
     self.task_manager.task_finished(task)
     # Assert
     assert self.task_manager.finished_tasks.qsize() == 1
     assert self.task_manager.finished_tasks.get() == task
Exemplo n.º 2
0
        def get_task_by_id(self, task_id):
            """Return a Task object of the specific task

            Arg:
                task_id (String): the id of the specific task

            Return:
                task: the Task object of the specific id
            """
            logger = Logger().get()
            logger.debug(f"start get_task_by_id, task_id:{task_id}")
            try:
                # Find the task using id
                condition = {"_id": ObjectId(task_id)}
                task_doc = self.__tasks_collection.find_one(condition)

                # Retrieve the output files and log files
                # Transform the dict into list of filenames
                output_list = []
                for filename in task_doc["output_files"].keys():
                    output_list.append(filename)

                # Rebuild the Task object from the query result
                task = Task()
                task.job_id = str(task_doc["job_id"])
                task.task_id = task_id
                task.program_name = task_doc['program_name']
                task.input_file_args = task_doc['input_file_args']
                task.input_text_args = task_doc['input_text_args']
                task.input_flag_args = task_doc['input_flag_args']
                task.output_file_args = task_doc['output_file_args']
                task.output = output_list
                task.stdout = task_doc["stdout"]
                task.stderr = task_doc["stderr"]
                task.status = Status(task_doc["status"])
                task.finished_time = task_doc["finished_time"]
                logger.debug(f"get_task_by_id successfully, task_id:{task_id}")
                return task
            except Exception as e:
                logger.error(f"something wrong in get_task_by_id, Exception: {e}")