Ejemplo n.º 1
0
    def poll(self, task_list=None, identity=None):
        """Polls for an activity task to process from current
        actor's instance defined ``task_list``

        if no activity task was polled, raises a PollTimeout
        exception.

        :param  task_list: task list the Actor should watch for tasks on
        :type   task_list: string

        :param  identity: Identity of the worker making the request,
                          which is recorded in the ActivityTaskStarted
                          event in the workflow history. This enables
                          diagnostic tracing when problems arise.
                          The form of this identity is user defined.
        :type   identity: string

        :raises: PollTimeout

        :returns: task token, polled activity task
        :rtype: (str, ActivityTask)
        """
        logging_context.reset()
        task_list = task_list or self.task_list
        identity = identity or self._identity

        try:
            task = self.connection.poll_for_activity_task(
                self.domain.name, task_list, identity=format.identity(identity),
            )
        except boto.exception.SWFResponseError as e:
            message = self.get_error_message(e)
            if e.error_code == "UnknownResourceFault":
                raise DoesNotExistError(
                    "Unable to poll activity task", message,
                )

            raise ResponseError(message)

        if not task.get("taskToken"):
            raise PollTimeout("Activity Worker poll timed out")

        logging_context.set("workflow_id", task["workflowExecution"]["workflowId"])
        logging_context.set("task_type", "activity")
        logging_context.set("event_id", task["startedEventId"])
        logging_context.set("activity_id", task["activityId"])

        activity_task = ActivityTask.from_poll(self.domain, self.task_list, task,)

        return Response(
            task_token=activity_task.task_token,
            activity_task=activity_task,
            raw_response=task,
        )
Ejemplo n.º 2
0
    def poll(self, task_list=None, identity=None):
        """Polls for an activity task to process from current
        actor's instance defined ``task_list``

        if no activity task was polled, raises a PollTimeout
        exception.

        :param  task_list: task list the Actor should watch for tasks on
        :type   task_list: string

        :param  identity: Identity of the worker making the request,
                          which is recorded in the ActivityTaskStarted
                          event in the workflow history. This enables
                          diagnostic tracing when problems arise.
                          The form of this identity is user defined.
        :type   identity: string

        :raises: PollTimeout

        :returns: task token, polled activity task
        :rtype: (str, ActivityTask)
        """
        task_list = task_list or self.task_list
        identity = identity or self._identity

        try:
            polled_activity_data = self.connection.poll_for_activity_task(
                self.domain.name, task_list, identity=identity)
        except boto.exception.SWFResponseError as e:
            message = self.get_error_message(e)
            if e.error_code == 'UnknownResourceFault':
                raise DoesNotExistError(
                    "Unable to poll activity task",
                    message,
                )

            raise ResponseError(message)

        if 'taskToken' not in polled_activity_data:
            raise PollTimeout("Activity Worker poll timed out")

        activity_task = ActivityTask.from_poll(self.domain, self.task_list,
                                               polled_activity_data)
        task_token = activity_task.task_token

        return task_token, activity_task
Ejemplo n.º 3
0
    def poll(self, task_list=None,
             identity=None,
             **kwargs):
        """
        Polls a decision task and returns the token and the full history of the
        workflow's events.

        :param task_list: task list to poll for decision tasks from.
        :type task_list: string

        :param identity: Identity of the decider making the request,
        which is recorded in the DecisionTaskStarted event in the
        workflow history.
        :type identity: string

        :returns: (token, history)
        :type: swf.models.History

        """
        task_list = task_list or self.task_list

        task = self.connection.poll_for_decision_task(
            self.domain.name,
            task_list=task_list,
            identity=identity,
            **kwargs
        )
        token = task.get('taskToken')
        if token is None:
            raise PollTimeout("Decider poll timed out")

        events = task['events']

        next_page = task.get('nextPageToken')
        while next_page:
            try:
                task = self.connection.poll_for_decision_task(
                    self.domain.name,
                    task_list=task_list,
                    identity=identity,
                    next_page_token=next_page,
                    **kwargs
                )
            except boto.exception.SWFResponseError as e:
                if e.error_code == 'UnknownResourceFault':
                    raise DoesNotExistError(
                        "Unable to poll decision task.\n",
                        e.body['message'],
                    )

                raise ResponseError(e.body['message'])

            token = task.get('taskToken')
            if token is None:
                raise PollTimeout("Decider poll timed out")

            events.extend(task['events'])
            next_page = task.get('nextPageToken')

        history = History.from_event_list(events)

        return token, history
Ejemplo n.º 4
0
    def poll(self, task_list=None, identity=None, **kwargs):
        """
        Polls a decision task and returns the token and the full history of the
        workflow's events.

        :param task_list: task list to poll for decision tasks from.
        :type task_list: str

        :param identity: Identity of the decider making the request,
        which is recorded in the DecisionTaskStarted event in the
        workflow history.
        :type identity: str

        :returns: a Response object with history, token, and execution set
        :rtype: swf.responses.Response

        """
        task_list = task_list or self.task_list

        task = self.connection.poll_for_decision_task(self.domain.name,
                                                      task_list=task_list,
                                                      identity=identity,
                                                      **kwargs)
        token = task.get('taskToken')
        if token is None:
            raise PollTimeout("Decider poll timed out")

        events = task['events']

        next_page = task.get('nextPageToken')
        while next_page:
            try:
                task = self.connection.poll_for_decision_task(
                    self.domain.name,
                    task_list=task_list,
                    identity=identity,
                    next_page_token=next_page,
                    **kwargs)
            except boto.exception.SWFResponseError as e:
                if e.error_code == 'UnknownResourceFault':
                    raise DoesNotExistError(
                        "Unable to poll decision task",
                        e.body['message'],
                    )

                raise ResponseError(e.body['message'])

            token = task.get('taskToken')
            if token is None:
                raise PollTimeout("Decider poll timed out")

            events.extend(task['events'])
            next_page = task.get('nextPageToken')

        history = History.from_event_list(events)

        workflow_type = WorkflowType(
            domain=self.domain,
            name=task['workflowType']['name'],
            version=task['workflowType']['version'],
        )
        execution = WorkflowExecution(
            domain=self.domain,
            workflow_id=task['workflowExecution']['workflowId'],
            run_id=task['workflowExecution']['runId'],
            workflow_type=workflow_type,
        )

        # TODO: move history into execution (needs refactoring on WorkflowExecution.history())
        return Response(token=token, history=history, execution=execution)
Ejemplo n.º 5
0
    def poll(self, task_list=None, identity=None, **kwargs):
        """
        Polls a decision task and returns the token and the full history of the
        workflow's events.

        :param task_list: task list to poll for decision tasks from.
        :type task_list: str

        :param identity: Identity of the decider making the request,
        which is recorded in the DecisionTaskStarted event in the
        workflow history.
        :type identity: str

        :returns: a Response object with history, token, and execution set
        :rtype: swf.responses.Response

        """
        logging_context.reset()
        task_list = task_list or self.task_list

        task = self.connection.poll_for_decision_task(
            self.domain.name,
            task_list=task_list,
            identity=format.identity(identity),
            **kwargs)
        token = task.get("taskToken")
        if not token:
            raise PollTimeout("Decider poll timed out")

        events = task["events"]
        logging_context.set("workflow_id",
                            task["workflowExecution"]["workflowId"])
        logging_context.set("task_type", "decision")
        logging_context.set("event_id", task["startedEventId"])

        next_page = task.get("nextPageToken")
        while next_page:
            try:
                task = self.connection.poll_for_decision_task(
                    self.domain.name,
                    task_list=task_list,
                    identity=format.identity(identity),
                    next_page_token=next_page,
                    **kwargs)
            except boto.exception.SWFResponseError as e:
                message = self.get_error_message(e)
                if e.error_code == "UnknownResourceFault":
                    raise DoesNotExistError(
                        "Unable to poll decision task",
                        message,
                    )

                raise ResponseError(message)

            token = task.get("taskToken")
            if not token:
                raise PollTimeout("Decider poll timed out")

            events.extend(task["events"])
            next_page = task.get("nextPageToken")

        history = History.from_event_list(events)

        workflow_type = WorkflowType(
            domain=self.domain,
            name=task["workflowType"]["name"],
            version=task["workflowType"]["version"],
        )
        execution = WorkflowExecution(
            domain=self.domain,
            workflow_id=task["workflowExecution"]["workflowId"],
            run_id=task["workflowExecution"]["runId"],
            workflow_type=workflow_type,
        )

        # TODO: move history into execution (needs refactoring on WorkflowExecution.history())
        return Response(token=token, history=history, execution=execution)