-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreporting-bot
42 lines (33 loc) · 1.15 KB
/
reporting-bot
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
#!/usr/bin/env/python
import asyncio
import logging
import os
import time
import environ
from psycopg2 import OperationalError
from reporting_bot import Config, ReportLoggingBot
if __name__ == '__main__':
config: Config = environ.to_config(Config)
LOGLEVEL = os.environ.get('LOGLEVEL', 'INFO').upper()
logging.basicConfig(level=LOGLEVEL)
logger = logging.getLogger(__name__)
while True:
try:
logger.debug('Creating Bot')
bot = ReportLoggingBot(config)
except OperationalError as err:
logger.warning('Could not connect to database')
logger.warning(err)
logger.warning('Retrying in 30 seconds')
# Try again in 30 seconds
time.sleep(30)
continue
# Split into separate try, to ensure database connection deconstruction
try:
logger.debug('Polling event info')
asyncio.run(bot.poll_events())
finally:
# Make sure the bot gets deconstructed and the database connection with it
del bot
logger.debug('Going to sleep again')
time.sleep(config.poll_interval)