Cleanup Routine
parent
828606584a
commit
b1e0fb23dc
|
@ -174,7 +174,7 @@ async def enviaCorreos():
|
||||||
|
|
||||||
try:
|
try:
|
||||||
rdestino = await db.execute(select(Destinatario).join(Direccion).join(FQDN).where(Destinatario.enviado==0).distinct(FQDN.id))
|
rdestino = await db.execute(select(Destinatario).join(Direccion).join(FQDN).where(Destinatario.enviado==0).distinct(FQDN.id))
|
||||||
tareas = []
|
|
||||||
for destinatario in rdestino.scalars():
|
for destinatario in rdestino.scalars():
|
||||||
result = await db.execute(select(Direccion).where(Direccion.id==destinatario.direccionid))
|
result = await db.execute(select(Direccion).where(Direccion.id==destinatario.direccionid))
|
||||||
dbemail = result.scalar_one_or_none()
|
dbemail = result.scalar_one_or_none()
|
||||||
|
@ -183,6 +183,27 @@ async def enviaCorreos():
|
||||||
except:
|
except:
|
||||||
await log.error('Traceback {}'.format(traceback.format_exc()))
|
await log.error('Traceback {}'.format(traceback.format_exc()))
|
||||||
|
|
||||||
|
async def cleanupSent():
|
||||||
|
from datetime import datetime, timedelta
|
||||||
|
returnvalue = True
|
||||||
|
oneMonth = datetime.now() - timedelta(days = 60)
|
||||||
|
|
||||||
|
try:
|
||||||
|
dest = await db.execute(select(Destinatario).where(Destinatario.timestamp<oneMonth, Destinatario.enviado>0).limit(1))
|
||||||
|
|
||||||
|
for destinatario in dest.scalars():
|
||||||
|
cartaid = destinatario.cartaid
|
||||||
|
await db.execute(delete(Destinatario).where(Destinatario.id==destinatario.id))
|
||||||
|
result = await db.execute(select(Destinatario).where(Destinatario.cartaid==cartaid))
|
||||||
|
more = result.scalar_one_or_none()
|
||||||
|
if more is None:
|
||||||
|
await db.execute(delete(Carta).where(Carta.id==cartaid))
|
||||||
|
returnvalue = False
|
||||||
|
|
||||||
|
except:
|
||||||
|
await log.error('Traceback {}'.format(traceback.format_exc()))
|
||||||
|
return returnvalue
|
||||||
|
|
||||||
|
|
||||||
def create_async_smtp_server():
|
def create_async_smtp_server():
|
||||||
handler = ilabHandler()
|
handler = ilabHandler()
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
from mayordomo import log, pre_process, enviaCorreos
|
from mayordomo import log, pre_process, enviaCorreos, cleanupSent
|
||||||
import os
|
import os
|
||||||
import daemon
|
import daemon
|
||||||
import time
|
import time
|
||||||
|
@ -19,7 +19,9 @@ def main():
|
||||||
while shouldIrun:
|
while shouldIrun:
|
||||||
if await pre_process():
|
if await pre_process():
|
||||||
await enviaCorreos()
|
await enviaCorreos()
|
||||||
await asyncio.sleep(10)
|
elif await cleanupSent():
|
||||||
|
await asyncio.sleep(10)
|
||||||
|
|
||||||
i = int(time.time())
|
i = int(time.time())
|
||||||
if i >= doki:
|
if i >= doki:
|
||||||
doki = i + hb
|
doki = i + hb
|
||||||
|
|
Loading…
Reference in New Issue