def release(self, g): self.__lock.acquire() try: if g in self.__graph_dict: removed = True if isinstance(g, ConjunctiveGraph): if 'persist' in app.config['STORE']: g.close() pool.submit(self.__clean, self.__graph_dict[g]) else: g.remove((None, None, None)) g.close() else: uuid = self.__graph_dict[g] if not r.sismember(self.__cache_key, uuid): resources_cache.remove_context(resources_cache.get_context(self.__graph_dict[g])) else: r.decr('{}:cache:{}:cnt'.format(AGENT_ID, uuid)) removed = False # The graph will be purged if removed: uuid = self.__graph_dict[g] del self.__graph_dict[g] del self.__uuid_dict[uuid] finally: self.__lock.release()
def register_enrichment(pipe, fid, target, links): e_hash = generate_enrichment_hash(target, links) if not r.sismember(enrichments_key, e_hash): eid = suuid() enrichment_data = EnrichmentData(eid, fid, target, links) enrichment_data.save(pipe) pipe.sadd(enrichments_key, e_hash) pipe.set('{}:map:enrichments:{}'.format(AGENT_ID, e_hash), eid) else: eid = r.get('{}:map:enrichments:{}'.format(AGENT_ID, e_hash)) return eid
def __get_fragment(fid): if not r.sismember('{}:fragments'.format(AGENT_ID), fid): raise NotFound('The fragment {} does not exist'.format(fid)) f_dict = { 'id': fid, 'gp': list(r.smembers('{}:fragments:{}:gp'.format(AGENT_ID, fid))), 'synced': r.exists('{}:fragments:{}:sync'.format(AGENT_ID, fid)), 'requests': list(r.smembers('{}:fragments:{}:requests'.format(AGENT_ID, fid))) } return f_dict
def get_fragment_graph(fid): if not r.sismember('{}:fragments'.format(AGENT_ID), fid): raise NotFound('The fragment {} does not exist'.format(fid)) lock = fragment_lock(fid) lock.acquire() try: response = make_response(fragment_graph(fid).serialize(format='turtle')) response.headers['Content-Type'] = 'text/turtle' finally: lock.release() return response