def _get_sessions(curs=None): from_d = datetime.datetime.now(pytz.utc) logger.info("Sessions dumping into db initiated %s", from_d) from_d = from_d - datetime.timedelta(minutes=settings.session_valid_minutes) logger.debug("Fetching not expired sessions, newer %s. Session valid period: %s minutes", from_d, settings.session_valid_minutes) f = SessionFilter({'from_update_date': from_d}, {}, ['id']) return f.filter_objs(curs)
def _clean(curs=None): to_d = datetime.datetime.now() logger.info("Sessions cleaning initiated %s", to_d) to_d = to_d - datetime.timedelta(minutes=settings.session_valid_minutes) logger.debug("Removing session older %s. Session valid period: %s minutes", to_d, settings.session_valid_minutes) f = SessionFilter({'to_update_date': to_d}, {}, ['id']) sessions = f.filter_objs(curs) logger.info("Deleting %s sessions", len(sessions)) mapping.delete_objects(curs, sessions) logger.info("Sessions cleaned")