def build_response(rid): from sdh.curator.actions import get_instance response_class = r.hget('requests:{}'.format(rid), '__response_class') if response_class is None: raise AttributeError('Cannot create a response for {}'.format(rid)) (module_name, class_name) = tuple(response_class.split('.')) return get_instance(module_name, class_name, rid)
def used_channels(): req_channel_keys = r.keys('requests:*') for rck in req_channel_keys: try: channel = r.hget(rck, 'channel') yield channel except Exception as e: log.warning(e.message)
def remove(self): with r.pipeline(transaction=True) as p: p.multi() action_id = r.hget(self._request_key, 'id') p.zrem('requests', action_id) r_keys = r.keys('{}*'.format(self._request_key)) for key in r_keys: p.delete(key) self._remove(p) p.execute() log.info('Request {} was removed'.format(self._request_id))
def _remove(self, pipe): super(DeliverySink, self)._remove(pipe) pipe.srem('deliveries', self._request_id) pipe.srem('deliveries:ready', self._request_id) channel_b64 = r.hget(self._request_key, 'channel') sharing = channel_sharing(channel_b64) if not sharing: log.info('Removing delivery channel ({}) for request {}'.format(channel_b64, self._request_id)) pipe.delete('channels:{}'.format(channel_b64)) else: log.info('Cannot remove delivery channel of request {}. It is being shared with {} another requests'.format( self.request_id, sharing))
def stream(self): return parse_bool(r.hget('requests:{}'.format(self._request_id), '__stream'))
def _remove(self, pipe): self._fragment_id = r.hget('{}'.format(self._request_key), 'fragment_id') pipe.srem('fragments:{}:requests'.format(self._fragment_id), self._request_id) super(FragmentSink, self)._remove(pipe)
def delivery(self): return r.hget('requests:{}'.format(self._request_id), 'delivery')