web/application.py
changeset 5328 c51e8f62652a
parent 5302 dfd147de06b2
parent 5326 0d9054eb3bd1
child 5385 b6e250dd7a7d
equal deleted inserted replaced
5327:34a298eca917 5328:c51e8f62652a
    36 
    36 
    37     def __init__(self, vreg):
    37     def __init__(self, vreg):
    38         self.session_time = vreg.config['http-session-time'] or None
    38         self.session_time = vreg.config['http-session-time'] or None
    39         if self.session_time is not None:
    39         if self.session_time is not None:
    40             assert self.session_time > 0
    40             assert self.session_time > 0
    41             self.session_time *= 60 # convert minutes to seconds
       
    42             self.cleanup_session_time = self.session_time
    41             self.cleanup_session_time = self.session_time
    43         else:
    42         else:
    44             self.cleanup_session_time = (vreg.config['cleanup-session-time'] or 1440) * 60
    43             self.cleanup_session_time = vreg.config['cleanup-session-time'] or 1440 * 60
    45             assert self.cleanup_session_time > 0
    44             assert self.cleanup_session_time > 0
    46         self.cleanup_anon_session_time = (vreg.config['cleanup-anonymous-session-time'] or 5) * 60
    45         self.cleanup_anon_session_time = vreg.config['cleanup-anonymous-session-time'] or 5 * 60
    47         assert self.cleanup_anon_session_time > 0
    46         assert self.cleanup_anon_session_time > 0
    48         self.authmanager = vreg['components'].select('authmanager', vreg=vreg)
    47         self.authmanager = vreg['components'].select('authmanager', vreg=vreg)
       
    48         if vreg.config.anonymous_user() is not None:
       
    49             self.clean_sessions_interval = min(
       
    50                 5 * 60,
       
    51                 self.cleanup_session_time / 2.,
       
    52                 self.cleanup_anon_session_time / 2.)
       
    53         else:
       
    54             self.clean_sessions_interval = min(
       
    55                 5 * 60,
       
    56                 self.cleanup_session_time / 2.)
    49 
    57 
    50     def clean_sessions(self):
    58     def clean_sessions(self):
    51         """cleanup sessions which has not been unused since a given amount of
    59         """cleanup sessions which has not been unused since a given amount of
    52         time. Return the number of sessions which have been closed.
    60         time. Return the number of sessions which have been closed.
    53         """
    61         """
   153         self.session_manager = self.vreg['components'].select('sessionmanager',
   161         self.session_manager = self.vreg['components'].select('sessionmanager',
   154                                                               vreg=self.vreg)
   162                                                               vreg=self.vreg)
   155         self.session_manager.restore_data(data)
   163         self.session_manager.restore_data(data)
   156         global SESSION_MANAGER
   164         global SESSION_MANAGER
   157         SESSION_MANAGER = self.session_manager
   165         SESSION_MANAGER = self.session_manager
       
   166 
       
   167     @property
       
   168     def clean_sessions_interval(self):
       
   169         return self.session_manager.clean_sessions_interval
   158 
   170 
   159     def clean_sessions(self):
   171     def clean_sessions(self):
   160         """cleanup sessions which has not been unused since a given amount of
   172         """cleanup sessions which has not been unused since a given amount of
   161         time
   173         time
   162         """
   174         """