Esempio n. 1
0
    def really_start(*args, **kwargs):
        """Use this function to start a workflow by passing in the args."""
        swf = swf_client if swf_client is not None else SWFClient()
        l_wid = wid  # closure hack
        if l_wid is None:
            l_wid = uuid.uuid4()
        if serialize_input is None:
            input_data = Proxy.serialize_input(*args, **kwargs)
        else:
            input_data = serialize_input(*args, **kwargs)
        if len(input_data) > INPUT_SIZE:
            logger.error(
                "Input too large: %s/%s" % (len(input_data), INPUT_SIZE))
            raise ValueError('Input too large.')
        try:
            r = swf.start_workflow_execution(
                domain, l_wid, name, version, input=input_data,
                priority=priority, task_list=task_list,
                execution_start_to_close_timeout=task_duration,
                task_start_to_close_timeout=workflow_duration,
                child_policy=child_policy, tags=tags, lambda_role=lambda_role)
        except ClientError as e:
            logger.exception('Error while starting the workflow:')
            raise e

        return r['runId']
Esempio n. 2
0
    def __call__(self, key, input_data, decision, *extra_args):
        """Execute the wrapped func registered with key passing the input_data.

        Any exra_args are also passed along to the wrapped_key.

        The actual actions are dispatched to the decision object and can be one
        of:
            * flush() - nothing to do, any pending actions should be commited
            * fail(e) - ignore pending actions, fail the execution
            * finish(e) - ignore pending actions, complete the execution
            * restart(serialized_input) - ignore pending actions, restart the execution
        """
        try:
            wrapped_func = self.registry[key]
        except KeyError:
            logger.error("Colud not find implementation for key: %r", (key,))
            return  # Let it timeout
        try:
            serialized_result = wrapped_func(input_data, *extra_args)
        except SuspendTask:
            decision.flush()
        except TaskError as e:
            logger.exception('Unhandled task error in task:')
            decision.fail(e)
        except Restart as e:
            decision.restart(e.input_data)
        except Exception as e:
            logger.exception('Unhandled exception in task:')
            decision.fail(e)
        else:
            decision.finish(serialized_result)
Esempio n. 3
0
    def __call__(self, key, input_data, decision, *extra_args):
        """Execute the wrapped func registered with key passing the input_data.

        Any exra_args are also passed along to the wrapped_key.

        The actual actions are dispatched to the decision object and can be one
        of:
            * flush() - nothing to do, any pending actions should be commited
            * fail(e) - ignore pending actions, fail the execution
            * finish(e) - ignore pending actions, complete the execution
            * restart(serialized_input) - ignore pending actions, restart the execution
        """
        try:
            wrapped_func = self.registry[key]
        except KeyError:
            logger.error("Colud not find implementation for key: %r", (key, ))
            return  # Let it timeout
        try:
            serialized_result = wrapped_func(input_data, *extra_args)
        except SuspendTask:  # only from workflows
            decision.flush()
        except TaskError as e:  # only from workflows
            logger.exception('Unhandled task error in task:')
            decision.fail(e)
        except Restart as e:  # only from workflows
            decision.restart(e.input_data)
        except Exception as e:
            logger.exception('Unhandled exception in task:')
            decision.fail(e)
        else:
            decision.finish(serialized_result)
Esempio n. 4
0
 def really_start(*args, **kwargs):
     """Use this function to start a workflow by passing in the args."""
     l1 = layer1 if layer1 is not None else Layer1()
     l_wid = wid  # closue hack
     if l_wid is None:
         l_wid = uuid.uuid4()
     if serialize_input is None:
         input_data = Proxy.serialize_input(*args, **kwargs)
     else:
         input_data = serialize_input(*args, **kwargs)
     if len(input_data) > INPUT_SIZE:
         logger.error("Input too large: %s/%s" % (len(input_data), INPUT_SIZE))
         raise ValueError('Input too large.')
     try:
         r = l1.start_workflow_execution(
             str(domain), str(l_wid), str(name), str(version),
             task_list=str_or_none(task_list),
             execution_start_to_close_timeout=str_or_none(workflow_duration),
             task_start_to_close_timeout=str_or_none(decision_duration),
             input=str(input_data),
             child_policy=cp_encode(child_policy),
             tag_list=tags_encode(tags))
     except SWFResponseError:
         logger.exception('Error while starting the workflow:')
         raise RuntimeError('Cannot start the workflow.')
     return r['runId']