Ejemplo n.º 1
0
def purgeExpiredSessions():
    botrunners = Session.query(BotRunner)
    for botrunner in botrunners:
        for session in botrunner.sessions:
            if session.lastpingtime != None:
                secondssincelastping = dates.timedifftototalseconds(datetime.datetime.now() - session.lastpingtime)
                if secondssincelastping > confighelper.getValue("expiresessionminutes") * 60:
                    expireBotRunnerSession(botrunner, session)
Ejemplo n.º 2
0
    def list(self):
        #FIXME: this should not be a part of a controller request
        botrunnerhelper.purgeExpiredSessions()
        Session.commit()

        botrunners = Session.query(BotRunner)

# if you know of a reliable way of just adding
#the following two data to  the business ojbects,
# go ahead:
        botrunnerdata = {}
        sessiondata = {}
        for botrunner in botrunners:
            rowspan = 1
            if len(botrunner.sessions) > 1:
                rowspan = len(botrunner.sessions)
            botrunnerdata[botrunner] = {}
            botrunnerdata[botrunner]['rowspan'] = rowspan
            for botSession in botrunner.sessions:
                sessiondata[botSession] = {}
                sessiondata[botSession]['pingtimestatus'] = 'down'
                if botSession.lastpingtime != None:
                    secondssincelastping = dates.timedifftototalseconds(
                            datetime.datetime.now() - botSession.lastpingtime)
                    sessiondata[botSession]['lastpingtimestring'] =\
                        str(botSession.lastpingtime)
                    if secondssincelastping < \
                        confighelper.getValue('expiresessionminutes') * 60:
                        sessiondata[botSession]['pingtimestatus'] = 'maybeok'
                    if secondssincelastping < confighelper.getValue(
                            'guimarksessionasmaybedownafterthismanyminutes') \
                            * 60:
                        sessiondata[botSession]['pingtimestatus'] = 'ok'

        c.botrunners = botrunners
        c.isIsLoggedIn = False
        if 'user' in session:
            c.isLoggedIn = True
            c.username = session['user']
        c.botrunnerData = botrunnerdata
        c.sessionData = sessiondata
        return render('viewbotrunners.html')