Skip to content

Commit

Permalink
Merge pull request hasgeek#295 from abijith-kp/master
Browse files Browse the repository at this point in the history
Add sweep command under manage.py. Fixes hasgeek#221
  • Loading branch information
jace committed Mar 31, 2016
2 parents c717b47 + 847114a commit 3d5bc0a
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion manage.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,30 @@
#!/usr/bin/env python

from coaster.manage import init_manager
from coaster.manage import init_manager, manager

import hasjob
import hasjob.models as models
import hasjob.forms as forms
import hasjob.views as views
from hasjob.models import db
from hasjob import app, init_for
from datetime import datetime, timedelta
from sqlalchemy.exc import IntegrityError

@manager.option('-e', '--env', default='dev', help="runtime env [default 'dev']")
def sweep(env):
"""Sweep the user database to close all the inactive sessions"""
manager.init_for(env)
print "Sweeping all the inactive sessions"
es = models.EventSession
# Inactive sessions are only kept for 30mins
es.query.filter((es.ended_at==None) & (es.active_at<(datetime.utcnow() - \
timedelta(minutes=30)))).update({es.ended_at: es.active_at})
try:
db.session.commit()
except IntegrityError:
print "Could not commit changes made. Please try again later."
db.session.rollback()


if __name__ == '__main__':
Expand Down

0 comments on commit 3d5bc0a

Please sign in to comment.