Beispiel #1
0
def persist_add(domein, botskey, value):
    ''' store persistent values in db.
    '''
    content = pickle.dumps(value, 0)
    if botsglobal.settings.DATABASE_ENGINE != 'sqlite3' and len(
            content) > 1024:
        raise botslib.PersistError(_(
            u'Data too long for domein "$domein", botskey "$botskey", value "$value".'
        ),
                                   domein=domein,
                                   botskey=botskey,
                                   value=value)
    try:
        botslib.change(
            u'''INSERT INTO persist (domein,botskey,content)
                                VALUES   (%(domein)s,%(botskey)s,%(content)s)''',
            {
                'domein': domein,
                'botskey': botskey,
                'content': content
            })
    except:
        raise botslib.PersistError(_(
            u'Failed to add for domein "$domein", botskey "$botskey", value "$value".'
        ),
                                   domein=domein,
                                   botskey=botskey,
                                   value=value)
Beispiel #2
0
def persist_delete(domein,botskey):
    ''' store persistent values in db.
    '''
    botslib.change(u'''DELETE FROM persist
                            WHERE domein=%(domein)s
                              AND botskey=%(botskey)s''',
                            {'domein':domein,'botskey':botskey})
Beispiel #3
0
def persist_delete(domein,botskey):
    ''' store persistent values in db.
    '''
    botslib.change(u'''DELETE FROM persist
                            WHERE domein=%(domein)s
                              AND botskey=%(botskey)s''',
                            {'domein':domein,'botskey':botskey})
def finish_evaluation(stuff2evaluate,resultlast,type):
    #count nr files send
    for row in botslib.query('''SELECT COUNT(*) as count
                                FROM  ta
                                WHERE idta > %(rootidta)s
                                AND status=%(status)s
                                AND statust=%(statust)s ''',
                                {'status':EXTERNOUT,'rootidta':stuff2evaluate,'statust':DONE}):
        send = row['count']
    #count process errors
    for row in botslib.query('''SELECT COUNT(*) as count
                                FROM  ta
                                WHERE idta >= %(rootidta)s
                                AND status=%(status)s
                                AND statust=%(statust)s''',
                                {'status':PROCESS,'rootidta':stuff2evaluate,'statust':ERROR}):
        processerrors = row['count']
    #generate report (in database)
    rootta=botslib.OldTransaction(stuff2evaluate)
    rootta.syn('ts')    #get the timestamp of this run
    LastReceived=resultlast[DONE]+resultlast[OK]+resultlast[OPEN]+resultlast[ERROR]
    status = bool(resultlast[OK]+resultlast[OPEN]+resultlast[ERROR]+processerrors)
    botslib.change(u'''INSERT INTO report (idta,lastopen,lasterror,lastok,lastdone,
                                            send,processerrors,ts,lastreceived,status,type)
                            VALUES  (%(idta)s,
                                    %(lastopen)s,%(lasterror)s,%(lastok)s,%(lastdone)s,
                                    %(send)s,%(processerrors)s,%(ts)s,%(lastreceived)s,%(status)s,%(type)s)
                            ''',
                            {'idta':stuff2evaluate,
                            'lastopen':resultlast[OPEN],'lasterror':resultlast[ERROR],'lastok':resultlast[OK],'lastdone':resultlast[DONE],
                            'send':send,'processerrors':processerrors,'ts':rootta.ts,'lastreceived':LastReceived,'status':status,'type':type[2:]})
    return generate_report(stuff2evaluate)    #return report status: 0 (no error) or 1 (error)
Beispiel #5
0
def _cleanprocessnothingreceived():
    ''' delete all --new runs that received no files; including all process under the run
        processes are organised as trees, so recursive.
    '''
    def core(idta):
        #select db-ta's referring to this db-ta
        for row in botslib.query('''SELECT idta
                                    FROM  ta
                                    WHERE idta > %(idta)s
                                    AND script=%(idta)s''',
                                    {'idta':idta}):
            core(row['idta'])
        ta=botslib.OldTransaction(idta)
        ta.delete()
        return 
    #select root-processes older than hoursnotrefferedarekept
    vanaf = datetime.datetime.today() - datetime.timedelta(hours=botsglobal.ini.getint('settings','hoursrunwithoutresultiskept',1))
    for row in botslib.query('''SELECT idta
                                FROM report
                                WHERE type = 'new'
                                AND lastreceived=0
                                AND ts < %(vanaf)s''',
                               {'vanaf':vanaf}):
        core(row['idta'])
        #delete report
        botslib.change('''DELETE FROM report WHERE idta=%(idta)s ''',{'idta':row['idta']})
Beispiel #6
0
def _cleanprocessnothingreceived():
    ''' delete all --new runs that recieved no files; including all process under the run
        processes are organised as trees, so recursive.
    '''
    def core(idta):
        #select db-ta's referring to this db-ta
        for row in botslib.query(
                '''SELECT idta
                                    FROM  ta
                                    WHERE idta > %(idta)s
                                    AND script=%(idta)s''', {'idta': idta}):
            core(row['idta'])
        ta = botslib.OldTransaction(idta)
        ta.delete()
        return

    #select root-processes older than hoursnotrefferedarekept
    vanaf = datetime.datetime.today() - datetime.timedelta(
        hours=botsglobal.ini.getint('settings', 'hoursrunwithoutresultiskept',
                                    1))
    for row in botslib.query(
            '''SELECT idta
                                FROM report
                                WHERE type = 'new'
                                AND lastreceived=0
                                AND ts < %(vanaf)s''', {'vanaf': vanaf}):
        core(row['idta'])
        #delete report
        botslib.change('''DELETE FROM report WHERE idta=%(idta)s ''',
                       {'idta': row['idta']})
Beispiel #7
0
def persist_delete(domein, botskey):
    """ store persistent values in db.
    """
    botslib.change(
        u"""DELETE FROM persist
                            WHERE domein=%(domein)s
                              AND botskey=%(botskey)s""",
        {"domein": domein, "botskey": botskey},
    )
Beispiel #8
0
def prepareretransmit():
    ''' prepare the retransmittable files. Return: indication if files should be retransmitted.'''
    retransmit = False  #indicate retransmit
    #for rereceive
    for row in botslib.query(
            '''SELECT idta,reportidta
                                FROM  filereport
                                WHERE retransmit=%(retransmit)s ''',
        {'retransmit': True}):
        retransmit = True
        botslib.change(
            '''UPDATE filereport
                           SET retransmit=%(retransmit)s
                           WHERE idta=%(idta)s
                           AND   reportidta=%(reportidta)s ''', {
                'idta': row['idta'],
                'reportidta': row['reportidta'],
                'retransmit': False
            })
        for row2 in botslib.query(
                '''SELECT idta
                                    FROM  ta
                                    WHERE parent=%(parent)s
                                    AND   status=%(status)s''', {
                    'parent': row['idta'],
                    'status': RAWIN
                }):
            ta_rereceive = botslib.OldTransaction(row2['idta'])
            ta_externin = ta_rereceive.copyta(
                status=EXTERNIN, statust=DONE, parent=0
            )  #inject; status is DONE so this ta is not used further
            ta_raw = ta_externin.copyta(
                status=RAWIN,
                statust=OK)  #reinjected file is ready as new input
    #for resend; this one is slow. Can be improved by having a separate list of idta to resend
    for row in botslib.query(
            '''SELECT idta,parent
                                FROM  ta
                                WHERE retransmit=%(retransmit)s
                                AND   status=%(status)s''', {
                'retransmit': True,
                'status': EXTERNOUT
            }):
        retransmit = True
        ta_outgoing = botslib.OldTransaction(row['idta'])
        ta_outgoing.update(
            retransmit=False)  #is reinjected; set retransmit back to False
        ta_resend = botslib.OldTransaction(
            row['parent']
        )  #parent ta with status RAWOUT; this is where the outgoing file is kept
        ta_externin = ta_resend.copyta(
            status=EXTERNIN, statust=DONE,
            parent=0)  #inject; status is DONE so this ta is not used further
        ta_raw = ta_externin.copyta(
            status=RAWOUT, statust=OK)  #reinjected file is ready as new input
    return retransmit
Beispiel #9
0
def persist_update(domein,botskey,value):
    ''' store persistent values in db.
    '''
    content = pickle.dumps(value,0)
    if botsglobal.settings.DATABASE_ENGINE != 'sqlite3' and len(content)>1024:
        raise botslib.PersistError(_(u'Data too long for domein "$domein", botskey "$botskey", value "$value".'),domein=domein,botskey=botskey,value=value)
    botslib.change(u'''UPDATE persist
                          SET content=%(content)s
                        WHERE domein=%(domein)s
                          AND botskey=%(botskey)s''',
                            {'domein':domein,'botskey':botskey,'content':content})
Beispiel #10
0
def persist_update(domein,botskey,value):
    ''' store persistent values in db.
    '''
    content = pickle.dumps(value,0)
    if botsglobal.settings.DATABASE_ENGINE != 'sqlite3' and len(content)>1024:
        raise botslib.PersistError(_(u'Data too long for domein "$domein", botskey "$botskey", value "$value".'),domein=domein,botskey=botskey,value=value)
    botslib.change(u'''UPDATE persist 
                          SET content=%(content)s
                        WHERE domein=%(domein)s
                          AND botskey=%(botskey)s''',
                            {'domein':domein,'botskey':botskey,'content':content})
def finish_evaluation(stuff2evaluate, resultlast, evaluate_type):
    #count nr files send
    for row in botslib.query(
            '''SELECT COUNT(*) as count
                                FROM  ta
                                WHERE idta > %(rootidta)s
                                AND status=%(status)s
                                AND statust=%(statust)s ''', {
                'status': EXTERNOUT,
                'rootidta': stuff2evaluate,
                'statust': DONE
            }):
        send = row['count']
    #count process errors
    for row in botslib.query(
            '''SELECT COUNT(*) as count
                                FROM  ta
                                WHERE idta >= %(rootidta)s
                                AND status=%(status)s
                                AND statust=%(statust)s''', {
                'status': PROCESS,
                'rootidta': stuff2evaluate,
                'statust': ERROR
            }):
        processerrors = row['count']
    #generate report (in database)
    rootta = botslib.OldTransaction(stuff2evaluate)
    rootta.syn('ts')  #get the timestamp of this run
    lastreceived = resultlast[DONE] + resultlast[OK] + resultlast[
        OPEN] + resultlast[ERROR]
    status = bool(resultlast[OK] + resultlast[OPEN] + resultlast[ERROR] +
                  processerrors)
    botslib.change(
        u'''INSERT INTO report (idta,lastopen,lasterror,lastok,lastdone,
                                            send,processerrors,ts,lastreceived,status,type)
                            VALUES  (%(idta)s,
                                    %(lastopen)s,%(lasterror)s,%(lastok)s,%(lastdone)s,
                                    %(send)s,%(processerrors)s,%(ts)s,%(lastreceived)s,%(status)s,%(type)s)
                            ''', {
            'idta': stuff2evaluate,
            'lastopen': resultlast[OPEN],
            'lasterror': resultlast[ERROR],
            'lastok': resultlast[OK],
            'lastdone': resultlast[DONE],
            'send': send,
            'processerrors': processerrors,
            'ts': rootta.ts,
            'lastreceived': lastreceived,
            'status': status,
            'type': evaluate_type[2:]
        })
    return generate_report(
        stuff2evaluate)  #return report status: 0 (no error) or 1 (error)
Beispiel #12
0
def persist_add(domein,botskey,value):
    ''' store persistent values in db.
    '''
    content = pickle.dumps(value,0)
    if botsglobal.settings.DATABASE_ENGINE != 'sqlite3' and len(content)>1024:
        raise botslib.PersistError(_(u'Data too long for domein "$domein", botskey "$botskey", value "$value".'),domein=domein,botskey=botskey,value=value)
    try:
        botslib.change(u'''INSERT INTO persist (domein,botskey,content)
                                VALUES   (%(domein)s,%(botskey)s,%(content)s)''',
                                {'domein':domein,'botskey':botskey,'content':content})
    except:
        raise botslib.PersistError(_(u'Failed to add for domein "$domein", botskey "$botskey", value "$value".'),domein=domein,botskey=botskey,value=value)
def finish_evaluation(stuff2evaluate, resultlast, evaluate_type):
    # count nr files send
    for row in botslib.query(
        """SELECT COUNT(*) as count
                                FROM  ta
                                WHERE idta > %(rootidta)s
                                AND status=%(status)s
                                AND statust=%(statust)s """,
        {"status": EXTERNOUT, "rootidta": stuff2evaluate, "statust": DONE},
    ):
        send = row["count"]
    # count process errors
    for row in botslib.query(
        """SELECT COUNT(*) as count
                                FROM  ta
                                WHERE idta >= %(rootidta)s
                                AND status=%(status)s
                                AND statust=%(statust)s""",
        {"status": PROCESS, "rootidta": stuff2evaluate, "statust": ERROR},
    ):
        processerrors = row["count"]
    # generate report (in database)
    rootta = botslib.OldTransaction(stuff2evaluate)
    rootta.syn("ts")  # get the timestamp of this run
    lastreceived = resultlast[DONE] + resultlast[OK] + resultlast[OPEN] + resultlast[ERROR]
    status = bool(resultlast[OK] + resultlast[OPEN] + resultlast[ERROR] + processerrors)
    botslib.change(
        u"""INSERT INTO report (idta,lastopen,lasterror,lastok,lastdone,
                                            send,processerrors,ts,lastreceived,status,type)
                            VALUES  (%(idta)s,
                                    %(lastopen)s,%(lasterror)s,%(lastok)s,%(lastdone)s,
                                    %(send)s,%(processerrors)s,%(ts)s,%(lastreceived)s,%(status)s,%(type)s)
                            """,
        {
            "idta": stuff2evaluate,
            "lastopen": resultlast[OPEN],
            "lasterror": resultlast[ERROR],
            "lastok": resultlast[OK],
            "lastdone": resultlast[DONE],
            "send": send,
            "processerrors": processerrors,
            "ts": rootta.ts,
            "lastreceived": lastreceived,
            "status": status,
            "type": evaluate_type[2:],
        },
    )
    return generate_report(stuff2evaluate)  # return report status: 0 (no error) or 1 (error)
Beispiel #14
0
def persist_update(domein, botskey, value):
    """ store persistent values in db.
    """
    content = pickle.dumps(value, 0)
    if botsglobal.settings.DATABASE_ENGINE != "sqlite3" and len(content) > 1024:
        raise botslib.PersistError(
            _(u'Data too long for domein "$domein", botskey "$botskey", value "$value".'),
            domein=domein,
            botskey=botskey,
            value=value,
        )
    botslib.change(
        u"""UPDATE persist 
                          SET content=%(content)s
                        WHERE domein=%(domein)s
                          AND botskey=%(botskey)s""",
        {"domein": domein, "botskey": botskey, "content": content},
    )
def insert_filereport(mytrace):
    botslib.change(
        u"""INSERT INTO filereport (idta,statust,reportidta,retransmit,idroute,fromchannel,ts,
                                                infilename,tochannel,frompartner,topartner,frommail,
                                                tomail,ineditype,inmessagetype,outeditype,outmessagetype,
                                                incontenttype,outcontenttype,nrmessages,outfilename,errortext,
                                                divtext,outidta,rsrv1)
                            VALUES  (%(idta)s,%(statust)s,%(reportidta)s,%(retransmit)s,%(idroute)s,%(fromchannel)s,%(ts)s,
                                    %(infilename)s,%(tochannel)s,%(frompartner)s,%(topartner)s,%(frommail)s,
                                    %(tomail)s,%(ineditype)s,%(inmessagetype)s,%(outeditype)s,%(outmessagetype)s,
                                    %(incontenttype)s,%(outcontenttype)s,%(nrmessages)s,%(outfilename)s,%(errortext)s,
                                    %(divtext)s,%(outidta)s,%(rsrv1)s )
                            """,
        {
            "idta": mytrace.idta,
            "statust": mytrace.statusttree,
            "reportidta": mytrace.reportidta,
            "retransmit": mytrace.retransmit,
            "idroute": mytrace.idroute,
            "fromchannel": mytrace.fromchannel,
            "ts": mytrace.ts,
            "infilename": mytrace.infilename,
            "tochannel": mytrace.tochannel,
            "frompartner": mytrace.frompartner,
            "topartner": mytrace.topartner,
            "frommail": mytrace.frommail,
            "tomail": mytrace.tomail,
            "ineditype": mytrace.ineditype,
            "inmessagetype": mytrace.inmessagetype,
            "outeditype": mytrace.outeditype,
            "outmessagetype": mytrace.outmessagetype,
            "incontenttype": mytrace.incontenttype,
            "outcontenttype": mytrace.outcontenttype,
            "nrmessages": mytrace.nrmessages,
            "outfilename": mytrace.outfilename,
            "errortext": mytrace.errortext,
            "divtext": mytrace.divtext,
            "outidta": mytrace.outidta,
            "rsrv1": mytrace.rsrv1,
        },
    )
def insert_filereport(mytrace):
    botslib.change(u'''INSERT INTO filereport (idta,statust,reportidta,retransmit,idroute,fromchannel,ts,
                                                infilename,tochannel,frompartner,topartner,frommail,
                                                tomail,ineditype,inmessagetype,outeditype,outmessagetype,
                                                incontenttype,outcontenttype,nrmessages,outfilename,errortext,
                                                divtext,outidta)
                            VALUES  (%(idta)s,%(statust)s,%(reportidta)s,%(retransmit)s,%(idroute)s,%(fromchannel)s,%(ts)s,
                                    %(infilename)s,%(tochannel)s,%(frompartner)s,%(topartner)s,%(frommail)s,
                                    %(tomail)s,%(ineditype)s,%(inmessagetype)s,%(outeditype)s,%(outmessagetype)s,
                                    %(incontenttype)s,%(outcontenttype)s,%(nrmessages)s,%(outfilename)s,%(errortext)s,
                                    %(divtext)s,%(outidta)s )
                            ''',
                            {'idta':mytrace.idta,'statust':mytrace.statusttree,'reportidta':mytrace.reportidta,
                            'retransmit':mytrace.retransmit,'idroute':mytrace.idroute,'fromchannel':mytrace.fromchannel,
                            'ts':mytrace.ts,'infilename':mytrace.infilename,'tochannel':mytrace.tochannel,
                            'frompartner':mytrace.frompartner,'topartner':mytrace.topartner,'frommail':mytrace.frommail,
                            'tomail':mytrace.tomail,'ineditype':mytrace.ineditype,'inmessagetype':mytrace.inmessagetype,
                            'outeditype':mytrace.outeditype,'outmessagetype':mytrace.outmessagetype,
                            'incontenttype':mytrace.incontenttype,'outcontenttype':mytrace.outcontenttype,
                            'nrmessages':mytrace.nrmessages,'outfilename':mytrace.outfilename,'errortext':mytrace.errortext,
                            'divtext':mytrace.divtext,'outidta':mytrace.outidta})
def insert_filereport(mytrace):
    botslib.change(
        u'''INSERT INTO filereport (idta,statust,reportidta,retransmit,idroute,fromchannel,ts,
                                                infilename,tochannel,frompartner,topartner,frommail,
                                                tomail,ineditype,inmessagetype,outeditype,outmessagetype,
                                                incontenttype,outcontenttype,nrmessages,outfilename,errortext,
                                                divtext,outidta,rsrv1)
                            VALUES  (%(idta)s,%(statust)s,%(reportidta)s,%(retransmit)s,%(idroute)s,%(fromchannel)s,%(ts)s,
                                    %(infilename)s,%(tochannel)s,%(frompartner)s,%(topartner)s,%(frommail)s,
                                    %(tomail)s,%(ineditype)s,%(inmessagetype)s,%(outeditype)s,%(outmessagetype)s,
                                    %(incontenttype)s,%(outcontenttype)s,%(nrmessages)s,%(outfilename)s,%(errortext)s,
                                    %(divtext)s,%(outidta)s,%(rsrv1)s )
                            ''', {
            'idta': mytrace.idta,
            'statust': mytrace.statusttree,
            'reportidta': mytrace.reportidta,
            'retransmit': mytrace.retransmit,
            'idroute': mytrace.idroute,
            'fromchannel': mytrace.fromchannel,
            'ts': mytrace.ts,
            'infilename': mytrace.infilename,
            'tochannel': mytrace.tochannel,
            'frompartner': mytrace.frompartner,
            'topartner': mytrace.topartner,
            'frommail': mytrace.frommail,
            'tomail': mytrace.tomail,
            'ineditype': mytrace.ineditype,
            'inmessagetype': mytrace.inmessagetype,
            'outeditype': mytrace.outeditype,
            'outmessagetype': mytrace.outmessagetype,
            'incontenttype': mytrace.incontenttype,
            'outcontenttype': mytrace.outcontenttype,
            'nrmessages': mytrace.nrmessages,
            'outfilename': mytrace.outfilename,
            'errortext': mytrace.errortext,
            'divtext': mytrace.divtext,
            'outidta': mytrace.outidta,
            'rsrv1': mytrace.rsrv1
        })
Beispiel #18
0
def prepareretransmit():
    ''' prepare the retransmittable files. Return: indication if files should be retransmitted.'''
    retransmit = False  #indicate retransmit
    #for rereceive
    for row in botslib.query('''SELECT idta,reportidta
                                FROM  filereport
                                WHERE retransmit=%(retransmit)s ''',
                                {'retransmit':True}):
        retransmit = True
        botslib.change('''UPDATE filereport
                           SET retransmit=%(retransmit)s
                           WHERE idta=%(idta)s
                           AND   reportidta=%(reportidta)s ''',
                            {'idta':row['idta'],'reportidta':row['reportidta'],'retransmit':False})
        for row2 in botslib.query('''SELECT idta
                                    FROM  ta
                                    WHERE parent=%(parent)s
                                    AND   status=%(status)s''',
                                    {'parent':row['idta'],
                                    'status':RAWIN}):
            ta_rereceive = botslib.OldTransaction(row2['idta'])
            ta_externin = ta_rereceive.copyta(status=EXTERNIN,statust=DONE,parent=0) #inject; status is DONE so this ta is not used further
            ta_raw = ta_externin.copyta(status=RAWIN,statust=OK)  #reinjected file is ready as new input
    #for resend; this one is slow. Can be improved by having a separate list of idta to resend
    for row in botslib.query('''SELECT idta,parent
                                FROM  ta
                                WHERE retransmit=%(retransmit)s
                                AND   status=%(status)s''',
                                {'retransmit':True,
                                'status':EXTERNOUT}):
        retransmit = True
        ta_outgoing = botslib.OldTransaction(row['idta'])
        ta_outgoing.update(retransmit=False)     #is reinjected; set retransmit back to False
        ta_resend = botslib.OldTransaction(row['parent'])  #parent ta with status RAWOUT; this is where the outgoing file is kept
        ta_externin = ta_resend.copyta(status=EXTERNIN,statust=DONE,parent=0) #inject; status is DONE so this ta is not used further
        ta_raw = ta_externin.copyta(status=RAWOUT,statust=OK)  #reinjected file is ready as new input
    return retransmit
Beispiel #19
0
def persist_add(domein, botskey, value):
    """ store persistent values in db.
    """
    content = pickle.dumps(value, 0)
    if botsglobal.settings.DATABASE_ENGINE != "sqlite3" and len(content) > 1024:
        raise botslib.PersistError(
            _(u'Data too long for domein "$domein", botskey "$botskey", value "$value".'),
            domein=domein,
            botskey=botskey,
            value=value,
        )
    try:
        botslib.change(
            u"""INSERT INTO persist (domein,botskey,content)
                                VALUES   (%(domein)s,%(botskey)s,%(content)s)""",
            {"domein": domein, "botskey": botskey, "content": content},
        )
    except:
        raise botslib.PersistError(
            _(u'Failed to add for domein "$domein", botskey "$botskey", value "$value".'),
            domein=domein,
            botskey=botskey,
            value=value,
        )
Beispiel #20
0
def _cleantransactions():
    vanaf = datetime.datetime.today() - datetime.timedelta(days=botsglobal.ini.getint('settings','maxdays',30))
    lijst = list( botslib.query('''SELECT idta FROM report WHERE ts < %(vanaf)s''',{'vanaf':vanaf}))
    for rootta in lijst:
        botslib.change('''DELETE FROM filereport WHERE reportidta = %(rootta)s''',{'rootta':rootta['idta']})
        botslib.change('''DELETE FROM report WHERE idta = %(rootta)s''',{'rootta':rootta['idta']})
        #~ botslib.change('''DELETE FROM filereport WHERE idta = %(rootta)s''',{'rootta':rootta['idta']})
    for index in range(1,len(lijst)):
        botslib.change('''DELETE FROM ta WHERE idta >= %(minrootta)s
                                         AND idta < %(maxrootta)s''',
                                         {'minrootta':lijst[index-1]['idta'],'maxrootta':lijst[index]['idta']})
Beispiel #21
0
def _cleantransactions():
    ''' delete records from report, filereport and ta.
        best indexes are on idta/reportidta; this should go fast.
    '''
    vanaf = datetime.datetime.today() - datetime.timedelta(days=botsglobal.ini.getint('settings','maxdays',30))
    for row in botslib.query('''SELECT max(idta) as max FROM report WHERE ts < %(vanaf)s''',{'vanaf':vanaf}):
        maxidta = row['max']
        break
    else:       #if there is no maxidta to delete, do nothing
        return
    botslib.change('''DELETE FROM report WHERE idta < %(maxidta)s''',{'maxidta':maxidta})
    botslib.change('''DELETE FROM filereport WHERE reportidta < %(maxidta)s''',{'maxidta':maxidta})
    botslib.change('''DELETE FROM ta WHERE idta < %(maxidta)s''',{'maxidta':maxidta})
Beispiel #22
0
def _cleantransactions():
    vanaf = datetime.datetime.today() - datetime.timedelta(
        days=botsglobal.ini.getint('settings', 'maxdays', 30))
    lijst = list(
        botslib.query('''SELECT idta FROM report WHERE ts < %(vanaf)s''',
                      {'vanaf': vanaf}))
    for rootta in lijst:
        botslib.change(
            '''DELETE FROM filereport WHERE reportidta = %(rootta)s''',
            {'rootta': rootta['idta']})
        botslib.change('''DELETE FROM report WHERE idta = %(rootta)s''',
                       {'rootta': rootta['idta']})
        #~ botslib.change('''DELETE FROM filereport WHERE idta = %(rootta)s''',{'rootta':rootta['idta']})
    for index in range(1, len(lijst)):
        botslib.change(
            '''DELETE FROM ta WHERE idta >= %(minrootta)s
                                         AND idta < %(maxrootta)s''', {
                'minrootta': lijst[index - 1]['idta'],
                'maxrootta': lijst[index]['idta']
            })
Beispiel #23
0
def _cleanpersist():
    '''delete all persist older than xx days.'''
    vanaf = datetime.datetime.today() - datetime.timedelta(
        days=botsglobal.ini.getint('settings', 'maxdayspersist', 30))
    botslib.change('''DELETE FROM persist WHERE ts < %(vanaf)s''',
                   {'vanaf': vanaf})
Beispiel #24
0
def _cleanupsession():
    ''' delete all expired sessions. Bots-engine starts up much more often than web-server.'''
    vanaf = datetime.datetime.today()
    botslib.change(
        '''DELETE FROM django_session WHERE expire_date < %(vanaf)s''',
        {'vanaf': vanaf})
Beispiel #25
0
def _cleanupsession():
    ''' delete all expired sessions. Bots-engine starts up much more often than web-server.'''
    vanaf = datetime.datetime.today()
    botslib.change('''DELETE FROM django_session WHERE expire_date < %(vanaf)s''', {'vanaf':vanaf})
Beispiel #26
0
def _cleanpersist():
    '''delete all persist older than xx days.'''
    vanaf = datetime.datetime.today() - datetime.timedelta(days=botsglobal.ini.getint('settings','maxdayspersist',30))
    botslib.change('''DELETE FROM persist WHERE ts < %(vanaf)s''',{'vanaf':vanaf})