Example #1
0
    def test_save_state_saves_alive_key_temporarily(self):
        self.monitor.save_state()

        key = Keys.get_blockchain_monitor_alive(self.monitor_name)
        last_update = self.redis.get(key)
        timeout = self.redis.time_to_live(key)

        self.assertIsNotNone(last_update)
        self.assertEqual(timeout, self.alive_key_timeout)
Example #2
0
    def save_state(self) -> None:
        # If Redis is enabled save the current time, indicating that the monitor
        # was alive at this time.
        if self.redis_enabled:
            self.logger.debug('Saving %s state', self._monitor_name)

            # Set alive key (to be able to query latest update from Telegram)
            key = Keys.get_blockchain_monitor_alive(self.monitor_name)
            until = timedelta(seconds=self._redis_alive_key_timeout)
            self.redis.set_for(key, str(datetime.now().timestamp()), until)