""" Workflow Service ================ Switch different type of workflow service. """ from ows_accounting import response from ows_accounting.utils import swf AMAZON_SIMPLE_WORKFLOW = 'swf' class WorkflowService(object): def __init__(self, service_name): """Switch to particular service. Args: service_name (str): workflow service name. Raises: Exception: if service is not supported or required method is not implemented in the particular service class. """ if service_name == AMAZON_SIMPLE_WORKFLOW: self.service = swf else: raise Exception( 'Service: {} is not supported.'.format(service_name)) def execute_workflow(self, workflow_id, correlation_id, **params): """Execute simple workflow. Args: workflow_id (str): workflow id which uniquely identify each workflow. correlation_id (str): correlation_id in the header. params (dict): report specific params. Returns: response.Response: Response object with message for success or failure. """ try: self.service.execute_workflow( workflow_id, correlation_id, **params) return response.Response(message='Workflow is executed.') except Exception as err: return response.create_fatal_response(str(err)) def generate_workflow_id(self, prefix, **params): """Generate workflow id from params. Args: prefix (str): prefix of workflow id. params (dict): user params for the workflow. Returns: response.Response: Response object with message for success or failure. If success. Message will be the workflow_id. """ try: workflow_id = self.service.generate_workflow_id(prefix, **params) return response.Response(message=workflow_id) except Exception as err: return response.Response(message=str(err), status=500)