Example #1
0
 def test_activity_id(self):
     activity_id = 20
     schedule_attributes = ScheduleActivityTaskDecisionAttributes()
     schedule_attributes.activity_id = activity_id
     self.decider.schedule_activity_task(schedule_attributes)
     self.assertEqual(
         0, self.decider.activity_id_to_scheduled_event_id[activity_id])
Example #2
0
 def test_schedule_activity_task(self):
     schedule_attributes = ScheduleActivityTaskDecisionAttributes()
     self.decider.schedule_activity_task(schedule_attributes)
     expected_decision_id = DecisionId(DecisionTarget.ACTIVITY, 0)
     self.assertEqual(1, self.decider.next_decision_event_id)
     self.assertEqual(1, len(self.decider.decisions))
     state_machine: ActivityDecisionStateMachine = self.decider.decisions[expected_decision_id]
     self.assertIs(schedule_attributes, state_machine.schedule_attributes)
     self.assertEqual(expected_decision_id, state_machine.id)
Example #3
0
    async def schedule_activity_task(self,
                                     parameters: ExecuteActivityParameters):
        attr = ScheduleActivityTaskDecisionAttributes()
        attr.activity_type = parameters.activity_type
        attr.input = parameters.input
        if parameters.heartbeat_timeout_seconds > 0:
            attr.heartbeat_timeout_seconds = parameters.heartbeat_timeout_seconds
        attr.schedule_to_close_timeout_seconds = parameters.schedule_to_close_timeout_seconds
        attr.schedule_to_start_timeout_seconds = parameters.schedule_to_start_timeout_seconds
        attr.start_to_close_timeout_seconds = parameters.start_to_close_timeout_seconds
        attr.activity_id = parameters.activity_id
        if not attr.activity_id:
            attr.activity_id = self.decider.get_and_increment_next_id()
        attr.task_list = TaskList()
        attr.task_list.name = parameters.task_list

        if parameters.retry_parameters:
            attr.retry_policy = parameters.retry_parameters.to_retry_policy()

        scheduled_event_id = self.decider.schedule_activity_task(schedule=attr)
        future = self.decider.event_loop.create_future()
        self.scheduled_activities[scheduled_event_id] = future
        try:
            await future
        except CancelledError as e:
            logger.debug("Coroutine cancelled (expected)")
            raise e
        except Exception as ex:
            pass
        ex = future.exception()
        if ex:
            activity_failure = ActivityFailureException(
                scheduled_event_id, parameters.activity_type.name,
                parameters.activity_id, serialize_exception(ex))
            raise activity_failure
        assert future.done()
        raw_bytes = future.result()
        return json.loads(str(raw_bytes, "utf-8"))
 def setUp(self) -> None:
     self.schedule_attributes = ScheduleActivityTaskDecisionAttributes()
     self.schedule_attributes.activity_id = "123"
     self.state_machine: ActivityDecisionStateMachine = ActivityDecisionStateMachine(
         DecisionId(DecisionTarget.ACTIVITY, 888),
         schedule_attributes=self.schedule_attributes)
Example #5
0
    async def schedule_activity_task(self, parameters: ExecuteActivityParameters):
        attr = ScheduleActivityTaskDecisionAttributes()
        attr.activity_type = parameters.activity_type
        attr.input = parameters.input
        if parameters.heartbeat_timeout_seconds > 0:
            attr.heartbeat_timeout_seconds = parameters.heartbeat_timeout_seconds
        attr.schedule_to_close_timeout_seconds = parameters.schedule_to_close_timeout_seconds
        attr.schedule_to_start_timeout_seconds = parameters.schedule_to_start_timeout_seconds
        attr.start_to_close_timeout_seconds = parameters.start_to_close_timeout_seconds
        attr.activity_id = parameters.activity_id
        if not attr.activity_id:
            attr.activity_id = self.decider.get_and_increment_next_id()
        attr.task_list = TaskList()
        attr.task_list.name = parameters.task_list

        # PORT: RetryParameters retryParameters = parameters.getRetryParameters();
        # PORT: if (retryParameters != null) {
        # PORT:    attributes.setRetryPolicy(retryParameters.toRetryPolicy());
        # PORT: }

        scheduled_event_id = self.decider.schedule_activity_task(schedule=attr)
        future = self.decider.event_loop.create_future()
        self.scheduled_activities[scheduled_event_id] = future
        await future
        assert future.done()
        exception = future.exception()
        if exception:
            raise exception
        raw_bytes = future.result()
        return json.loads(str(raw_bytes, "utf-8"))