示例#1
0
 def post(self, request, book, page, operation, task_id):
     try:
         op_status = operation_worker.status(task_id)
         if op_status.code == TaskStatusCodes.FINISHED:
             result = operation_worker.pop_result(task_id)
             result['status'] = op_status.to_dict()
             return Response(result)
         elif op_status.code == TaskStatusCodes.ERROR:
             error = operation_worker.pop_result(task_id)
             raise error
         else:
             return Response({'status': op_status.to_dict()})
     except TaskNotFoundException:
         return Response({'status': TaskStatus().to_dict()})
     except KeyError as e:
         logger.exception(e)
         return APIError(
             status.HTTP_400_BAD_REQUEST,
             "Invalid request. See server error logs for further information.",
             "Invalid request",
             ErrorCodes.OPERATION_INVALID_GET,
         ).response()
     except (FileNotFoundError, OSError) as e:
         logger.error(e)
         return Response({'error': 'no-model'},
                         status=status.HTTP_500_INTERNAL_SERVER_ERROR)
     except Exception as e:
         logging.error(e)
         return Response({'error': 'unknown'},
                         status=status.HTTP_500_INTERNAL_SERVER_ERROR)
示例#2
0
    def get(self, request, book, operation):
        book = DatabaseBook(book)
        body = json.loads(request.body, encoding='utf-8') if request.body else {}
        task_runner = BookOperationView.op_to_task_runner(operation, book, body)
        if task_runner is not None:
            task_id = operation_worker.id_by_task_runner(task_runner)
            op_status = operation_worker.status(task_id)
            if op_status:
                return Response({'status': op_status.to_dict()})
            else:
                return Response(status.HTTP_204_NO_CONTENT)

        return Response(status=status.HTTP_204_NO_CONTENT)
示例#3
0
 def post(self, request, book, operation, task_id):
     try:
         op_status = operation_worker.status(task_id)
         if op_status.code == TaskStatusCodes.FINISHED:
             result = operation_worker.pop_result(task_id)
             result['status'] = op_status.to_dict()
             return Response(result)
         elif op_status.code == TaskStatusCodes.ERROR:
             error = operation_worker.pop_result(task_id)
             if isinstance(error, Exception):
                 raise error
             logger.error("Error in task: {} (status: )".format(error, op_status))
             return Response(error, status=status.HTTP_500_INTERNAL_SERVER_ERROR)
         else:
             return Response({'status': op_status.to_dict()})
     except TaskNotFoundException as e:
         return APIError(status.HTTP_404_NOT_FOUND,
                         "Task was not found.",
                         "Task not found.",
                         ErrorCodes.OPERATION_TASK_NOT_FOUND,
                         ).response()
     except KeyError as e:
         logger.exception(e)
         return APIError(status.HTTP_400_BAD_REQUEST,
                         "Invalid request. See server error logs for further information.",
                         "Invalid request",
                         ErrorCodes.OPERATION_INVALID_GET,
                         ).response()
     except (FileNotFoundError, OSError, IOError) as e:
         logger.exception(e)
         return APIError(status.HTTP_400_BAD_REQUEST,
                         "Model not found",
                         "No model was found",
                         ErrorCodes.OPERATION_TASK_NO_MODEL).response()
     except EmptyDataSetException as e:
         logger.exception(e)
         return APIError(status.HTTP_400_BAD_REQUEST,
                         "Dataset is empty",
                         "No ground truth files available",
                         ErrorCodes.OPERATION_TASK_TRAIN_EMPTY_DATASET,
                         ).response()
     except Exception as e:
         logging.exception(e)
         return APIError(status.HTTP_500_INTERNAL_SERVER_ERROR,
                         str(e),
                         "Unknown server error",
                         ErrorCodes.OPERATION_UNKNOWN_SERVER_ERROR,
                         ).response()
示例#4
0
 def get(self, request, book, operation, task_id):
     op_status = operation_worker.status(task_id)
     if op_status:
         return Response({'status': op_status.to_dict()})
     else:
         return Response(status=status.HTTP_204_NO_CONTENT)