forked from mitro-co/emailer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
emailer.py
43 lines (31 loc) · 933 Bytes
/
emailer.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!/usr/bin/env python
import logging
import time
import signal
import config
import database
import providers
import queue
interrupted = False
def main():
logging.root.setLevel(logging.INFO)
logging.info("Starting up email queue")
session = database.get_session(config.database)
provider = providers.get_provider(config.provider)
processor = queue.QueueProcessor(config, session, provider)
try:
while not interrupted:
logging.debug("checking email queue")
processor.process()
time.sleep(config.queue.getfloat('sleep_seconds', 10))
except Exception as e:
logging.critical(e.message)
finally:
database.close_connection()
def signal_handler(signal, frame):
global interrupted
interrupted = True
logging.info("Shutting down email queue")
signal.signal(signal.SIGINT, signal_handler)
if __name__ == '__main__':
main()