Ejemplo n.º 1
0
 def fake_poll(self):
     polled_activity_data = json.loads(b64decode(self.poll_data))
     activity_task = BaseActivityTask.from_poll(
         self.domain, self.task_list, polled_activity_data,
     )
     return Response(
         task_token=activity_task.task_token,
         activity_task=activity_task,
         raw_response=polled_activity_data,
     )
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)
        """
        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.º 3
0
 def fake_poll(self):
     polled_activity_data = json.loads(b64decode(self.poll_data))
     activity_task = BaseActivityTask.from_poll(
         self.domain,
         self.task_list,
         polled_activity_data,
     )
     return Response(
         task_token=activity_task.task_token,
         activity_task=activity_task,
         raw_response=polled_activity_data,
     )
Ejemplo n.º 4
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: polled activity task
        :type: swf.models.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:
            if e.error_code == 'UnknownResourceFault':
                raise DoesNotExistError(
                    "Unable to poll activity task.\n",
                    e.body['message']
                )

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

        if not 'taskToken' 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.º 5
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.º 6
0
    def test_dispatch_is_catched_correctly(self):
        domain = Domain("test-domain")
        poller = ActivityPoller(domain, "task-list")

        # this activity does not exist, so it will provoke an
        # ImportError when dispatching
        activity_type = FakeActivityType("activity.does.not.exist")
        task = ActivityTask(domain, "task-list", activity_type=activity_type)

        worker = ActivityWorker()

        with patch.object(poller, "fail_with_retry") as mock:
            worker.process(poller, "token", task)

        self.assertEquals(1, mock.call_count)
        self.assertEquals(mock.call_args[0], ("token", task))
        self.assertIn("No module named ", mock.call_args[1]["reason"])
Ejemplo n.º 7
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 'taskToken' not in task:
            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,
        )