def compute_stampede_db_url(): """ If the requested endpoint requires connecting to a STAMPEDE database, then determine STAMPEDE DB URL and store it in g.stampede_db_url. Also, set g.m_wf_id to be the root workflow's uuid """ if "/workflow" not in request.path or "m_wf_id" not in g: return md5sum = hashlib.md5() md5sum.update(g.master_db_url.encode("utf-8")) m_wf_id = g.m_wf_id def _get_cache_key(key_suffix): return "%s.%s" % (md5sum.hexdigest(), key_suffix) cache_key = _get_cache_key(m_wf_id) if cache.get(cache_key): log.debug("Cache Hit: compute_stampede_db_url %s" % cache_key) root_workflow = cache.get(cache_key) else: log.debug("Cache Miss: compute_stampede_db_url %s" % cache_key) queries = MasterWorkflowQueries(g.master_db_url) root_workflow = queries.get_root_workflow(m_wf_id) queries.close() cache.set(_get_cache_key(root_workflow.wf_id), root_workflow, timeout=600) cache.set(_get_cache_key(root_workflow.wf_uuid), root_workflow, timeout=600) g.url_m_wf_id = root_workflow.wf_id g.m_wf_id = root_workflow.wf_uuid g.stampede_db_url = root_workflow.db_url
def compute_stampede_db_url(): """ If the requested endpoint requires connecting to a STAMPEDE database, then determine STAMPEDE DB URL and store it in g.stampede_db_url. Also, set g.m_wf_id to be the root workflow's uuid """ if '/workflow' not in request.path or 'm_wf_id' not in g: return md5sum = hashlib.md5() md5sum.update(g.master_db_url) m_wf_id = g.m_wf_id def _get_cache_key(key_suffix): return '%s.%s' % (md5sum.hexdigest(), key_suffix) cache_key = _get_cache_key(m_wf_id) if cache.get(cache_key): log.debug('Cache Hit: compute_stampede_db_url %s' % cache_key) root_workflow = cache.get(cache_key) else: log.debug('Cache Miss: compute_stampede_db_url %s' % cache_key) queries = MasterWorkflowQueries(g.master_db_url) root_workflow = queries.get_root_workflow(m_wf_id) queries.close() cache.set(_get_cache_key(root_workflow.wf_id), root_workflow, timeout=600) cache.set(_get_cache_key(root_workflow.wf_uuid), root_workflow, timeout=600) g.url_m_wf_id = root_workflow.wf_id g.m_wf_id = root_workflow.wf_uuid g.stampede_db_url = root_workflow.db_url
def _get_all(self, q, use_cache=True, timeout=60): cache_key = '%s.all' % self._cache_key_from_query(q) if use_cache and cache.get(cache_key): log.debug('Cache Hit: %s' % cache_key) record = cache.get(cache_key) else: log.debug('Cache Miss: %s' % cache_key) record = q.all() t = timeout(record) if hasattr(timeout, '__call__') else timeout cache.set(cache_key, record, t) return record
def _get_count(self, q, use_cache=True, timeout=60): cache_key = '%s.count' % self._cache_key_from_query(q) if use_cache and cache.get(cache_key): log.debug('Cache Hit: %s' % cache_key) count = cache.get(cache_key) else: log.debug('Cache Miss: %s' % cache_key) count = q.count() t = timeout(count) if hasattr(timeout, '__call__') else timeout cache.set(cache_key, count, t) return count