Beispiel #1
0
    def workflow_response(self, task_id, task_starttime, debug_flush=False):

        app_context.init()
        app_context.application_context = {}

        input_files, workflow_id, jobid, tool_name, step_order = file_ops.json_input_format(self.json_data)
        log_info("workflow_response started the response generation", app_context.application_context)
        error_validator = ValidationResponse(self.DOWNLOAD_FOLDER)
        try:
            error_validator.wf_keyerror(jobid, workflow_id, tool_name, step_order)
            error_validator.inputfile_list_error(input_files)
            output_file_response = list()
            for i, item in enumerate(input_files):
                input_filename, in_file_type, in_locale     = file_ops.accessing_files(item)
                self.json_data['taskID']                   = task_id
                app_context.application_context             = self.json_data
                
                if debug_flush == False:
                    bm_response = DocumentStructure(app_context=app_context, file_name=input_filename, lang=in_locale)
                    if bm_response['code'] == 200:
                        
                        output_filename_json = file_ops.writing_json_file(i, bm_response['rsp'], self.DOWNLOAD_FOLDER)
                        file_res = file_ops.one_filename_response(input_filename, output_filename_json, in_locale, in_file_type)
                        output_file_response.append(file_res)
                        task_endtime = str(time.time()).replace('.', '')
                        response_true = CustomResponse(Status.SUCCESS.value, jobid, task_id)
                        response_success = response_true.success_response(workflow_id, task_starttime, task_endtime, tool_name, step_order, output_file_response)
                        response = copy.deepcopy(response_success)
                        log_info("successfully generated response for workflow", app_context.application_context)
                        
                        return response
                    else:
                        post_error_wf(bm_response.code, bm_response.message, app_context.application_context, None)
                        return None
                else:
                    log_info('flushing queue data, not handling file {}'.format(input_files), app_context.application_context)
                    post_error_wf(400, 'flushing queue data, not handling file {}'.format(input_files), app_context.application_context, None)
                    return None

            
        except WorkflowkeyError as e:
            response_custom = CustomResponse(Status.ERR_STATUS.value, jobid, task_id)
            response_custom.status_code['message'] = str(e)
            response = file_ops.error_handler(response_custom.status_code, "WORKFLOWKEY-ERROR", True)
            log_exception("workflow_response workflow key error: key value missing", app_context.application_context, e)
            response = copy.deepcopy(response)
            return response
        except FileErrors as e:
            response_custom = CustomResponse(Status.ERR_STATUS.value, jobid, task_id)
            response_custom.status_code['message'] = e.message
            response = file_ops.error_handler(response_custom.status_code, e.code, True)
            log_exception("workflow_response some error occured while validating file", app_context.application_context, e)
            response = copy.deepcopy(response)
            return response
        except ServiceError as e:
            response_custom = CustomResponse(Status.ERR_STATUS.value, jobid, task_id)
            response_custom.status_code['message'] = str(e)
            response = file_ops.error_handler(response_custom.status_code, "SERVICE_ERROR", True)
            log_exception("workflow_response Something went wrong during pdf to block conversion.", app_context.application_context, e)
            response = copy.deepcopy(response)
            return response
Beispiel #2
0
 def workflow_response(self, task_id, task_starttime):
     input_files, workflow_id, jobid, tool_name, step_order = file_ops.json_input_format(
         self.json_data)
     log_info("workflow_response", "started the response generation", jobid)
     error_validator = ValidationResponse(self.DOWNLOAD_FOLDER)
     try:
         error_validator.wf_keyerror(jobid, workflow_id, tool_name,
                                     step_order)
         error_validator.inputfile_list_error(input_files)
         output_file_response = list()
         for i, item in enumerate(input_files):
             input_filename, in_file_type, in_locale = file_ops.accessing_files(
                 item)
             output_json_data = DocumentStructure(jobid=jobid,
                                                  file_name=input_filename,
                                                  lang=in_locale)
             output_filename_json = file_ops.writing_json_file(
                 i, output_json_data, self.DOWNLOAD_FOLDER)
             file_res = file_ops.one_filename_response(
                 input_filename, output_filename_json, in_locale,
                 in_file_type)
             output_file_response.append(file_res)
         task_endtime = str(time.time()).replace('.', '')
         response_true = CustomResponse(Status.SUCCESS.value, jobid,
                                        task_id)
         response_success = response_true.success_response(
             workflow_id, task_starttime, task_endtime, tool_name,
             step_order, output_file_response)
         response = copy.deepcopy(response_success)
         log_info("workflow_response",
                  "successfully generated response for workflow", jobid)
         return response
     except WorkflowkeyError as e:
         response_custom = CustomResponse(Status.ERR_STATUS.value, jobid,
                                          task_id)
         response_custom.status_code['message'] = str(e)
         response = file_ops.error_handler(response_custom.status_code,
                                           "WORKFLOWKEY-ERROR", True)
         log_exception("workflow_response",
                       "workflow key error: key value missing", jobid, e)
         response = copy.deepcopy(response)
         return response
     except FileErrors as e:
         response_custom = CustomResponse(Status.ERR_STATUS.value, jobid,
                                          task_id)
         response_custom.status_code['message'] = e.message
         response = file_ops.error_handler(response_custom.status_code,
                                           e.code, True)
         log_exception("workflow_response",
                       "some error occured while validating file", jobid, e)
         response = copy.deepcopy(response)
         return response
     except ServiceError as e:
         response_custom = CustomResponse(Status.ERR_STATUS.value, jobid,
                                          task_id)
         response_custom.status_code['message'] = str(e)
         response = file_ops.error_handler(response_custom.status_code,
                                           "SERVICE_ERROR", True)
         log_exception(
             "workflow_response",
             "Something went wrong during pdf to block conversion.", jobid,
             e)
         response = copy.deepcopy(response)
         return response
Beispiel #3
0
    def workflow_response(self, task_id, task_starttime):

        app_context.init()
        app_context.application_context = self.json_data

        input_params, workflow_id, jobid, tool_name, step_order = file_ops.json_input_format(
            self.json_data)
        log_info("workflow_response started the response generation",
                 app_context.application_context)
        error_validator = ValidationResponse(self.DOWNLOAD_FOLDER)

        try:
            error_validator.wf_keyerror(jobid, workflow_id, tool_name,
                                        step_order)

            # --------------------------

            result = process_incoming_request(app_context, input_params[0],
                                              jobid, workflow_id)

            # --------------------------

            task_endtime = eval(str(time.time()).replace('.', '')[0:13])
            response_true = CustomResponse(Status.SUCCESS.value, jobid,
                                           task_id)
            response_success = response_true.success_response(
                workflow_id, task_starttime, task_endtime, tool_name,
                step_order, result)
            log_info(
                "workflow_response : successfully generated response for workflow",
                app_context.application_context)
            return response_success

        except WorkflowkeyError as e:
            response_custom = CustomResponse(Status.ERR_STATUS.value, jobid,
                                             task_id)
            response_custom.status_code['message'] = str(e)
            response = file_ops.error_handler(response_custom.status_code,
                                              "WORKFLOWKEY-ERROR", True)
            log_exception(
                "workflow_response workflow key error: key value missing",
                app_context.application_context, e)
            response = copy.deepcopy(response)
            return response
        except FileErrors as e:
            response_custom = CustomResponse(Status.ERR_STATUS.value, jobid,
                                             task_id)
            response_custom.status_code['message'] = e.message
            response = file_ops.error_handler(response_custom.status_code,
                                              e.code, True)
            log_exception(
                "workflow_response some error occured while validating file",
                app_context.application_context, e)
            response = copy.deepcopy(response)
            return response
        except ServiceError as e:
            response_custom = CustomResponse(Status.ERR_STATUS.value, jobid,
                                             task_id)
            response_custom.status_code['message'] = str(e)
            response = file_ops.error_handler(response_custom.status_code,
                                              "SERVICE_ERROR", True)
            log_exception("workflow_response Something went wrong during ocr.",
                          app_context.application_context, e)
            response = copy.deepcopy(response)
            return response