Пример #1
0
    async def register_reminder(self, name: str, state: bytes,
                                due_time: timedelta,
                                period: timedelta) -> None:
        """Registers actor reminder.

        Reminders are a mechanism to trigger persistent callbacks on an actor at specified times.
        Their functionality is similar to timers. But unlike timers, reminders are triggered under
        all circumstances until the actor explicitly unregisters them or the actor is explicitly
        deleted. Specifically, reminders are triggered across actor deactivations and failovers
        because the Actors runtime persists information about the actor's reminders using actor
        state provider. Also existing reminders can be updated by calling this registration method
        again using the same reminderName.

        Args:
            name (str): the name of the reminder to register. the name must be unique per actor.
            state (bytes): the user state passed to the reminder invocation.
            due_time (datetime.timedelta): the amount of time to delay before invoking the reminder
                for the first time.
            period (datetime.timedelta): the time interval between reminder invocations after
                the first invocation.
        """
        reminder = ActorReminderData(name, state, due_time, period)
        req_body = self._runtime_ctx.message_serializer.serialize(
            reminder.as_dict())
        await self._runtime_ctx.dapr_client.register_reminder(
            self._runtime_ctx.actor_type_info.type_name, self.id.id, name,
            req_body)
Пример #2
0
 def test_as_dict(self):
     reminder = ActorReminderData('test_reminder', b'reminder_state',
                                  timedelta(seconds=1),
                                  timedelta(seconds=1))
     expected = {
         'reminderName': 'test_reminder',
         'dueTime': timedelta(seconds=1),
         'period': timedelta(seconds=1),
         'data': 'cmVtaW5kZXJfc3RhdGU=',
     }
     self.assertDictEqual(expected, reminder.as_dict())