You seem to have an old version of session2strash.py. The new one only uses 
self.expiration and not expiration.

On Sunday, 9 August 2015 10:15:57 UTC-5, Bob St John wrote:
>
> Using 2.12.1
>
> I run a small site... about 200 members who login (some using the 
> 'Remember me for 30 days') plus about 1500 public visitors per day. The 
> sessions are stored in the file system. I run the sessions2trash.py script 
> once a day. I have noticed the sessions are increasing by about 1000 per 
> day which did not seem right. I made the following changes to trash() and 
> now the sessions remaining after being 'trashed' is about 200-300, which 
> seems correct. I think the problem was when a large expiration was saved 
> (30 days) and the next expired public sessions were not trashed....
>
>
> CURRENT TRASH:
>     def trash(self):
>         """Trash expired sessions."""
>         now = datetime.datetime.now()
>         for item in self.get():
>             status = 'OK'
>             last_visit = item.last_visit_default()
>
>             try:
>                 session = item.get()
>                 if session.auth:
>                     if session.auth.expiration and not self.force:
>                         self.expiration = session.auth.expiration
>                     if session.auth.last_visit:
>                         last_visit = session.auth.last_visit
>             except:
>                 pass
>
>             age = 0
>             if last_visit:
>                 age = total_seconds(now - last_visit)
>
>             if age > self.expiration or not self.expiration:
>                 item.delete()
>                 status = 'trashed'
>
>             if self.verbose > 1:
>                 print 'key: %s' % str(item)
>                 print 'expiration: %s seconds' % self.expiration
>                 print 'last visit: %s' % str(last_visit)
>                 print 'age: %s seconds' % age
>                 print 'status: %s' % status
>                 print ''
>             elif self.verbose > 0:
>                 print('%s %s' % (str(item), status))
>
> MODIFIED TRASH:
>     def trash(self):
>         """Trash expired sessions."""
>         now = datetime.datetime.now()
>         for item in self.get():
>             status = 'OK'
>             last_visit = item.last_visit_default()
>             expiration = self.expiration ### added this
>
>             try:
>                 session = item.get()
>                 if session.auth:
>                     if session.auth.expiration and not self.force:
>                         ###self.expiration = session.auth.expiration
>                         expiration = session.auth.expiration
>                     if session.auth.last_visit:
>                         last_visit = session.auth.last_visit
>             except:
>                 pass
>
>             age = 0
>             if last_visit:
>                 age = total_seconds(now - last_visit)
>
>             ###if age > self.expiration or not self.expiration:
>             if age > expiration or not expiration:
>                 item.delete()
>                 status = 'trashed'
>
>             if self.verbose > 1:
>                 print 'key: %s' % str(item)
>                 print 'expiration: %s seconds' % self.expiration
>                 print 'last visit: %s' % str(last_visit)
>                 print 'age: %s seconds' % age
>                 print 'status: %s' % status
>                 print ''
>             elif self.verbose > 0:
>                 print('%s %s' % (str(item), status))
>
>

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to