Ejemplo n.º 1
0
 def dong_listener(payload: EventDongPayload):
     log.debug('receive <dong> event <%s>', payload)
     self.emit('dong', payload.data)
     # feed food to the dog
     food = WatchdogFood(timeout=30)
     if self._watchdog:
         self._watchdog.feed(food)
Ejemplo n.º 2
0
        async def start_watchdog():
            try:
                self._watchdog = Watchdog(DEFAULT_TIMEOUT)
                watch_dog_id = id(self._watchdog)
                food = WatchdogFood(timeout=3)

                async def ask_for_food(last_food, last_feed):
                    log.debug('dog ask for food <%s> <%s> ...', last_food,
                              last_feed)
                    # Cancel when stopped, or the puppet.ding() call will got an error
                    if self.puppet and self._watchdog and id(
                            self._watchdog) == watch_dog_id:
                        await self.puppet.ding()

                self._watchdog.on('sleep', ask_for_food)
                self._watchdog.feed(food)
                # If we set _watchdog to None or a new one, this loop should break.
                while self._watchdog and id(self._watchdog) == watch_dog_id:
                    log.debug('bot tick <%s>', datetime.now())
                    await self._watchdog.sleep()
                    is_death = self._watchdog.starved_to_death()
                    if is_death:
                        await self.restart()
                        break
            except asyncio.CancelledError:
                # When we stop the bot, we call cancel on the self._watchdog_task.
                # In this case, a CancelledError will raise then, just exit this function
                # to terminate the watchdog
                pass
Ejemplo n.º 3
0
        async def start_watchdog():

            food = WatchdogFood(timeout=3)

            async def ask_for_food(last_food, last_feed):
                log.debug('dog ask for food <%s> <%s> ...',
                          last_food, last_feed)
                await self.puppet.ding()

            self._watchdog.on('sleep', ask_for_food)
            self._watchdog.feed(food)
            while True:
                log.debug('bot tick <%s>', datetime.now())
                await self._watchdog.sleep()
                is_death = self._watchdog.starved_to_death()
                if is_death:
                    await self.restart()
                    break