pysmtp/sender.py

42 lines
839 B
Python
Raw Permalink Normal View History

2022-07-16 15:41:13 -04:00
from mayordomo import log, pre_process, enviaCorreos, cleanupSent
2021-12-29 15:06:40 -03:00
import os
2021-12-28 03:01:00 -03:00
import daemon
import time
import signal
import asyncio
2021-12-29 15:03:19 -03:00
if not os.environ.get('HEARTBEAT'):
hb = 60 * 15 # 15 minutos
else:
hb = int(os.environ.get('HEARTBEAT'))
2022-01-21 01:36:23 -03:00
shouldIrun = True
2021-12-29 15:03:19 -03:00
2021-12-28 03:01:00 -03:00
def main():
async def main_loop():
await log.info('Demonio iniciado')
2021-12-29 15:03:19 -03:00
doki = int(time.time()) + hb
2022-01-21 01:36:23 -03:00
while shouldIrun:
2021-12-28 03:01:00 -03:00
if await pre_process():
await enviaCorreos()
2022-07-16 15:41:13 -04:00
elif await cleanupSent():
await asyncio.sleep(10)
2021-12-28 03:01:00 -03:00
i = int(time.time())
if i >= doki:
2021-12-29 15:03:19 -03:00
doki = i + hb
2021-12-28 03:01:00 -03:00
await log.info('Heartbeat')
def run():
signal.signal(signal.SIGTERM, programCleanup)
asyncio.run(main_loop())
2022-01-21 01:28:25 -03:00
def programCleanup(_signo, _stack_frame):
2022-01-21 01:31:59 -03:00
log.info('Recibida señal de salida!')
2022-01-21 01:36:23 -03:00
shouldIrun = False
2021-12-28 03:01:00 -03:00
run()
if __name__ == '__main__':
main()