Beispiel #1
0
class ChannelStatusWorker(BaseWorker):
    '''This worker consumes status messages for the transport, and stores them
    in redis. Statuses with the same component are overwritten. It can also
    optionally forward the statuses to a URL'''
    CONFIG_CLASS = ChannelStatusConfig

    @inlineCallbacks
    def setup_connectors(self):
        connector = yield self.setup_receive_status_connector(
            "%s.status" % (self.config['channel_id'], ))
        connector.set_status_handler(self.consume_status)

    @inlineCallbacks
    def setup_worker(self):
        redis = yield TxRedisManager.from_config(self.config['redis_manager'])
        self.store = StatusStore(redis, ttl=None)
        yield self.unpause_connectors()

    def teardown_worker(self):
        pass

    @inlineCallbacks
    def consume_status(self, status):
        '''Store the status in redis under the correct component'''
        yield self.store.store_status(self.config['channel_id'], status)

        if self.config.get('status_url') is not None:
            yield self.send_status(status)

    @inlineCallbacks
    def send_status(self, status):
        data = api_from_status(self.config['channel_id'], status)
        config = self.get_static_config()
        resp = yield post(config.status_url,
                          data,
                          timeout=config.status_url_timeout)

        if resp and request_failed(resp):
            logging.exception(
                'Error sending status event, received HTTP code %r with '
                'body %r. Status event: %r' % (resp.code,
                                               (yield resp.content()), status))
Beispiel #2
0
class ChannelStatusWorker(BaseWorker):
    '''This worker consumes status messages for the transport, and stores them
    in redis. Statuses with the same component are overwritten. It can also
    optionally forward the statuses to a URL'''
    CONFIG_CLASS = ChannelStatusConfig

    @inlineCallbacks
    def setup_connectors(self):
        connector = yield self.setup_receive_status_connector(
            "%s.status" % (self.config['channel_id'],))
        connector.set_status_handler(self.consume_status)

    @inlineCallbacks
    def setup_worker(self):
        redis = yield TxRedisManager.from_config(self.config['redis_manager'])
        self.store = StatusStore(redis, ttl=None)
        yield self.unpause_connectors()

    def teardown_worker(self):
        pass

    @inlineCallbacks
    def consume_status(self, status):
        '''Store the status in redis under the correct component'''
        yield self.store.store_status(self.config['channel_id'], status)

        if self.config.get('status_url') is not None:
            yield self.send_status(status)

    @inlineCallbacks
    def send_status(self, status):
        data = api_from_status(self.config['channel_id'], status)
        config = self.get_static_config()
        resp = yield post(config.status_url, data,
                          timeout=config.status_url_timeout)

        if resp and request_failed(resp):
            logging.exception(
                'Error sending status event, received HTTP code %r with '
                'body %r. Status event: %r'
                % (resp.code, (yield resp.content()), status))