class LocationsPoller(BasePoller): def __init__(self, heartbeat, config): BasePoller.__init__(self, heartbeat, config) self.api = LocationsApi(config) self.logger = get_logger('locations_poller') self.register_event('locations', subscribable=True) self._locations = [] def bootstrap_listener(self, listener): self._locations = self._get_locations() self.emit_to_listener(listener, 'locations', self._locations) def sleep(self): time.sleep(0.2) @throttle(1, instance_method=True) def poll(self): self.logger.debug('Polling locations') locations = self._get_locations() if len(locations) != len(self._locations): self.emit('locations', self._get_locations()) def _get_locations(self): return self.api.query({})
def __init__(self, heartbeat, config): BasePoller.__init__(self, heartbeat, config) self.api = LocationsApi(config) self.logger = get_logger('locations_poller') self.register_event('locations', subscribable=True) self._locations = []