Пример #1
0
class LinksPoller(BasePoller):

    def __init__(self, heartbeat, config):
        BasePoller.__init__(self, heartbeat, config)
        self.api = LinksApi(config)
        self.logger = get_logger('links_poller')
        self.register_event('links', subscribable=True)
        self._links = self._get_links()

    def bootstrap_listener(self, listener):
        self._get_links()
        self.emit_to_listener(listener, 'links', self._links)

    def sleep(self):
        time.sleep(0.2)

    @throttle(1, instance_method=True)
    def poll(self):
        self.logger.debug('Polling links')
        links = self._get_links()

        if len(links) != len(self._links):
            self.emit('links', links)

    def _get_links(self):
        return self.api.query({})
Пример #2
0
 def __init__(self, heartbeat, config):
     BasePoller.__init__(self, heartbeat, config)
     self.api = LinksApi(config)
     self.logger = get_logger('links_poller')
     self.register_event('links', subscribable=True)
     self._links = self._get_links()