Changeset 1392
- Timestamp:
- 02/22/07 16:32:40 (6 years ago)
- File:
-
- 1 edited
-
ccsd/trunk/crcnetd/_utils/ccsd_session.py (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
ccsd/trunk/crcnetd/_utils/ccsd_session.py
r1391 r1392 870 870 def sessionMaintenance(*args, **kwargs): 871 871 """Checks for expired sessions and removes them""" 872 start = time.time() 873 asession = getSessionE(ADMIN_SESSION_ID) 874 875 # Loop through the list of sessions and remove expired ones 876 for sessionID,session in ccsd_session.sessions.items(): 877 # Never expire the admin session 878 if sessionID==ADMIN_SESSION_ID: continue 879 if session.isExpired(): continue 880 # Not expired, update db expiry time if we're expiring "soon" 881 if session.lifetime() < MAINT_INTERVAL * 3: 882 sql = "UPDATE sessions SET expires=%s WHERE sid=%s" 883 res = asession.execute(sql, \ 884 (time.ctime(session.expires), session.session_id)) 885 886 # Also delete expired login cookies 887 session = getSessionE(ADMIN_SESSION_ID) 888 sql = "DELETE FROM cookies WHERE expires<NOW()" 889 res = session.execute(sql, ()) 890 log_debug("Session maintenance completed successfully in %.3f seconds" % \ 891 (time.time()-start)) 892 872 global sessionLock 873 874 # Ensure that only one thread is executing session maintenance at once 875 if not sessionLock.acquire(False): 876 log_warn("A previous session maintenance task is still in progress!") 877 return 878 try: 879 ct = threading.currentThread() 880 ct.setName("sessionMaintenance") 881 start = time.time() 882 asession = getSessionE(ADMIN_SESSION_ID) 883 884 # Loop through the list of sessions and remove expired ones 885 for sessionID,session in ccsd_session.sessions.items(): 886 # Never expire the admin session 887 if sessionID==ADMIN_SESSION_ID: continue 888 if session.isExpired(): continue 889 # Not expired, update db expiry time if we're expiring "soon" 890 if session.lifetime() < MAINT_INTERVAL * 3: 891 sql = "UPDATE sessions SET expires=%s WHERE sid=%s" 892 res = asession.execute(sql, \ 893 (time.ctime(session.expires), session.session_id)) 894 895 # Also delete expired login cookies 896 session = getSessionE(ADMIN_SESSION_ID) 897 sql = "DELETE FROM cookies WHERE expires<NOW()" 898 res = session.execute(sql, ()) 899 log_debug("Session maintenance completed successfully in %.3f " \ 900 "seconds" % (time.time()-start)) 901 except: 902 log_error("Failed to complete session maintenace", sys.exc_info()) 903 sessionLock.release() 904 893 905 @catchEvent("shutdown") 894 906 def shutdownSessions(*args, **kwargs): … … 1160 1172 ##################################################################### 1161 1173 def initSessions(): 1174 global sessionLock 1162 1175 try: 1163 1176 # Get database connection parameters … … 1179 1192 # Load any other saved sessions 1180 1193 ccsd_session.sessions.update(loadSessions()) 1194 1195 # Initialise the lock 1196 sessionLock = threading.RLock() 1181 1197 1182 1198 log_info("Successfully loaded sessions")
Note: See TracChangeset
for help on using the changeset viewer.
