class FlowCompletionTasks {

    public void updateRequestDbStatus(BuildingBlockExecution execution) {

        try {
            String requestId = execution.getGeneralBuildingBlock().getRequestContext().getMsoRequestId();
            InfraActiveRequests request = requestDbclient.getInfraActiveRequestbyRequestId(requestId);

            WorkflowException workflowException = (WorkflowException) execution.getVariable("WorkflowException");
            if (workflowException == null) {
                request.setStatusMessage("RequestCompletedSuccessfully");
                request.setRequestStatus("COMPLETE");

            } else {
                request.setStatusMessage(workflowException.getErrorMessage());
                request.setRequestStatus("FAILED");
            }
            request.setProgress(100L);
            request.setLastModifiedBy("CamundaBPMN");

            requestDbclient.updateInfraActiveRequests(request);
        } catch (Exception e) {
            logger.error("Unable to save the updated request status to the DB", e);
        }
    }

}