-
Notifications
You must be signed in to change notification settings - Fork 1
/
rsvpbot.py
44 lines (32 loc) · 904 Bytes
/
rsvpbot.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
44
#Do this early in case anything depends on .env
from dotenv import load_dotenv, find_dotenv
load_dotenv(find_dotenv())
from threading import Thread
import traceback
import signal
from bot import run_bot
from poller import run_poller
import atom
running = atom.Atom(True)
def shutdown(signum, frame):
running.value = False
print("RSVPBot shutting down...")
def keep_alive(f, *args):
def wrapped():
while True:
try:
f(*args)
except Exception as e:
print(traceback.format_exc())
return wrapped
def start():
signal.signal(signal.SIGTERM, shutdown)
signal.signal(signal.SIGINT, shutdown)
bot = Thread(target=keep_alive(run_bot, running))
bot.start()
poller = Thread(target=keep_alive(run_poller, running))
poller.start()
bot.join()
poller.join()
if __name__ == "__main__":
start()