server/sources/pyrorql.py
changeset 6957 ffda12be2e9f
parent 6946 e350771c23a3
child 6958 861251f125cf
equal deleted inserted replaced
6956:b172c383dbce 6957:ffda12be2e9f
   166                 timestamp = int(rset[0][0])
   166                 timestamp = int(rset[0][0])
   167             return datetime.fromtimestamp(timestamp)
   167             return datetime.fromtimestamp(timestamp)
   168         finally:
   168         finally:
   169             session.close()
   169             session.close()
   170 
   170 
   171     def init(self, activated, session=None):
   171     def init(self, activated, source_entity):
   172         """method called by the repository once ready to handle request"""
   172         """method called by the repository once ready to handle request"""
   173         self.load_mapping(session)
   173         self.load_mapping(source_entity._cw)
   174         if activated:
   174         if activated:
   175             interval = self.config['synchronization-interval']
   175             interval = self.config['synchronization-interval']
   176             self.repo.looping_task(interval, self.synchronize)
   176             self.repo.looping_task(interval, self.synchronize)
   177             self.repo.looping_task(self._query_cache.ttl.seconds/10,
   177             self.repo.looping_task(self._query_cache.ttl.seconds/10,
   178                                    self._query_cache.clear_expired)
   178                                    self._query_cache.clear_expired)
   182         self.support_relations = {}
   182         self.support_relations = {}
   183         self.dont_cross_relations = set(('owned_by', 'created_by'))
   183         self.dont_cross_relations = set(('owned_by', 'created_by'))
   184         self.cross_relations = set()
   184         self.cross_relations = set()
   185         assert self.eid is not None
   185         assert self.eid is not None
   186         self._schemacfg_idx = {}
   186         self._schemacfg_idx = {}
   187         if session is None:
   187         self._load_mapping(session)
   188             _session = self.repo.internal_session()
       
   189         else:
       
   190             _session = session
       
   191         try:
       
   192             for schemacfg in _session.execute(
       
   193                 'Any CFG,CFGO,SN,S WHERE '
       
   194                 'CFG options CFGO, CFG cw_schema S, S name SN, '
       
   195                 'CFG cw_for_source X, X eid %(x)s', {'x': self.eid}).entities():
       
   196                 self.add_schema_config(schemacfg)
       
   197         finally:
       
   198             if session is None:
       
   199                 _session.close()
       
   200 
   188 
   201     etype_options = set(('write',))
   189     etype_options = set(('write',))
   202     rtype_options = set(('maycross', 'dontcross', 'write',))
   190     rtype_options = set(('maycross', 'dontcross', 'write',))
   203 
   191 
   204     def _check_options(self, schemacfg, allowedoptions):
   192     def _check_options(self, schemacfg, allowedoptions):