コード例 #1
0
def exec_query(workflow_client: WorkflowClient,
               qm: QueryMethod,
               args,
               stub_instance: object = None):
    assert stub_instance._execution
    request = QueryWorkflowRequest()
    request.execution = stub_instance._execution
    request.query = WorkflowQuery()
    request.query.query_type = qm.name
    request.query.query_args = args_to_json(args)
    request.domain = workflow_client.domain
    response: QueryWorkflowResponse
    response, err = workflow_client.service.query_workflow(request)
    if err:
        if isinstance(err, QueryFailedError):
            cause = deserialize_exception(err.message)
            raise QueryFailureException(
                query_type=qm.name,
                execution=stub_instance._execution) from cause
        elif isinstance(err, Exception):
            raise err
        else:
            raise Exception(err)
    if response.query_rejected:
        raise QueryRejectedException(response.query_rejected.close_status)
    return json.loads(response.query_result)
コード例 #2
0
 async def stub_activity_fn(self, *args):
     assert self._decision_context
     assert stub_activity_fn._execute_parameters
     parameters = copy.deepcopy(stub_activity_fn._execute_parameters)
     parameters.input = args_to_json(args).encode("utf-8")
     from cadence.decision_loop import DecisionContext
     decision_context: DecisionContext = self._decision_context
     return await decision_context.schedule_activity_task(parameters=parameters)
コード例 #3
0
def exec_signal(workflow_client: WorkflowClient, sm: SignalMethod, args, stub_instance: object = None):
    assert stub_instance._execution
    request = SignalWorkflowExecutionRequest()
    request.workflow_execution = stub_instance._execution
    request.signal_name = sm.name
    request.input = args_to_json(args)
    request.domain = workflow_client.domain
    response, err = workflow_client.service.signal_workflow_execution(request)
    if err:
        raise Exception(err)
コード例 #4
0
 async def stub_activity_fn(self, *args):
     assert self._decision_context
     assert stub_activity_fn._execute_parameters
     parameters = copy.deepcopy(stub_activity_fn._execute_parameters)
     if hasattr(self, "_activity_options") and self._activity_options:
         self._activity_options.fill_execute_activity_parameters(
             parameters)
     if self._retry_parameters:
         parameters.retry_parameters = self._retry_parameters
     parameters.input = args_to_json(args).encode("utf-8")
     from cadence.decision_loop import DecisionContext
     decision_context: DecisionContext = self._decision_context
     return await decision_context.schedule_activity_task(
         parameters=parameters)
コード例 #5
0
def create_start_workflow_request(workflow_client: WorkflowClient, wm: WorkflowMethod,
                                  args: List) -> StartWorkflowExecutionRequest:
    start_request = StartWorkflowExecutionRequest()
    start_request.domain = workflow_client.domain
    start_request.workflow_id = wm._workflow_id if wm._workflow_id else str(uuid4())
    start_request.workflow_type = WorkflowType()
    start_request.workflow_type.name = wm._name
    start_request.task_list = TaskList()
    start_request.task_list.name = wm._task_list
    start_request.input = args_to_json(args)
    start_request.execution_start_to_close_timeout_seconds = wm._execution_start_to_close_timeout_seconds
    start_request.task_start_to_close_timeout_seconds = wm._task_start_to_close_timeout_seconds
    start_request.identity = workflow_client.service.get_identity()
    start_request.workflow_id_reuse_policy = wm._workflow_id_reuse_policy
    start_request.request_id = str(uuid4())
    start_request.cron_schedule = wm._cron_schedule if wm._cron_schedule else None
    return start_request