class UpdateDeviceLastContact(SeleneScript): def __init__(self): super(UpdateDeviceLastContact, self).__init__(__file__) self.cache = SeleneCache() def _run(self): device_repo = DeviceRepository(self.db) devices_updated = 0 for device in device_repo.get_all_device_ids(): last_contact_ts = self._get_ts_from_cache(device.id) if last_contact_ts is not None: devices_updated += 1 device_repo.update_last_contact_ts(device.id, last_contact_ts) self.log.info(str(devices_updated) + ' devices were active today') def _get_ts_from_cache(self, device_id): last_contact_ts = None cache_key = DEVICE_LAST_CONTACT_KEY.format(device_id=device_id) value = self.cache.get(cache_key) if value is not None: last_contact_ts = datetime.strptime(value.decode(), '%Y-%m-%d %H:%M:%S.%f') self.cache.delete(cache_key) return last_contact_ts
def delete_device_login(device_id: str, cache: SeleneCache): session = cache.get("device.session:{uuid}".format(uuid=device_id)) if session is not None: session = json.loads(session) access_token = session["accessToken"] cache.delete( "device.token.access:{access}".format(access=access_token)) refresh_token = session["refreshToken"] cache.delete( "device.refresh.token:{refresh}".format(refresh=refresh_token)) cache.delete("device.session:{uuid}".format(uuid=device_id))
def _clean_cache(): """Remove testing data from the Redis database.""" cache = SeleneCache() cache.delete("pairing.token:this is a token")
def _clean_cache(): cache = SeleneCache() cache.delete('pairing.token:this is a token')