server/repository.py
changeset 6012 d56fd78006cd
parent 5920 6c0a7a881024
child 6013 8ca424bc393b
equal deleted inserted replaced
6011:b5f15098f282 6012:d56fd78006cd
   265         if not (self.config.creating or self.config.repairing
   265         if not (self.config.creating or self.config.repairing
   266                 or self.config.quick_start):
   266                 or self.config.quick_start):
   267             # call instance level initialisation hooks
   267             # call instance level initialisation hooks
   268             self.hm.call_hooks('server_startup', repo=self)
   268             self.hm.call_hooks('server_startup', repo=self)
   269             # register a task to cleanup expired session
   269             # register a task to cleanup expired session
   270             self.looping_task(self.config['session-time']/3., self.clean_sessions)
   270             self.cleanup_session_time = self.config['cleanup-session-time'] or 60 * 60 * 24
       
   271             assert self.cleanup_session_time > 0
       
   272             cleanup_session_interval = min(60*60, self.cleanup_session_time / 3)
       
   273             self.looping_task(cleanup_session_interval, self.clean_sessions)
   271         assert isinstance(self._looping_tasks, list), 'already started'
   274         assert isinstance(self._looping_tasks, list), 'already started'
   272         for i, (interval, func, args) in enumerate(self._looping_tasks):
   275         for i, (interval, func, args) in enumerate(self._looping_tasks):
   273             self._looping_tasks[i] = task = utils.LoopTask(interval, func, args)
   276             self._looping_tasks[i] = task = utils.LoopTask(interval, func, args)
   274             self.info('starting task %s with interval %.2fs', task.name,
   277             self.info('starting task %s with interval %.2fs', task.name,
   275                       interval)
   278                       interval)
   620             return self.type_and_source_from_eid(eid, session)
   623             return self.type_and_source_from_eid(eid, session)
   621         finally:
   624         finally:
   622             session.reset_pool()
   625             session.reset_pool()
   623 
   626 
   624     def check_session(self, sessionid):
   627     def check_session(self, sessionid):
   625         """raise `BadConnectionId` if the connection is no more valid"""
   628         """raise `BadConnectionId` if the connection is no more valid, else
   626         self._get_session(sessionid, setpool=False)
   629         return its latest activity timestamp.
       
   630         """
       
   631         return self._get_session(sessionid, setpool=False).timestamp
   627 
   632 
   628     def get_shared_data(self, sessionid, key, default=None, pop=False):
   633     def get_shared_data(self, sessionid, key, default=None, pop=False):
   629         """return the session's data dictionary"""
   634         """return the session's data dictionary"""
   630         session = self._get_session(sessionid, setpool=False)
   635         session = self._get_session(sessionid, setpool=False)
   631         return session.get_shared_data(key, default, pop)
   636         return session.get_shared_data(key, default, pop)
   769 
   774 
   770     def clean_sessions(self):
   775     def clean_sessions(self):
   771         """close sessions not used since an amount of time specified in the
   776         """close sessions not used since an amount of time specified in the
   772         configuration
   777         configuration
   773         """
   778         """
   774         mintime = time() - self.config['session-time']
   779         mintime = time() - self.cleanup_session_time
   775         self.debug('cleaning session unused since %s',
   780         self.debug('cleaning session unused since %s',
   776                    strftime('%T', localtime(mintime)))
   781                    strftime('%T', localtime(mintime)))
   777         nbclosed = 0
   782         nbclosed = 0
   778         for session in self._sessions.values():
   783         for session in self._sessions.values():
   779             if session.timestamp < mintime:
   784             if session.timestamp < mintime: