-
Notifications
You must be signed in to change notification settings - Fork 1
/
uploader.py
73 lines (60 loc) · 2 KB
/
uploader.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
from configparser import ConfigParser, NoSectionError, NoOptionError
import logging
import os.path
import sys
import threading
import time
from flask import Flask
import zingest.db
from logger import init_logger
from zingest.opencast import Opencast
from zingest.rabbit import Rabbit
from zingest.zoom import Zoom
init_logger()
logger = logging.getLogger(__name__)
logger.info("Startup")
try:
config = ConfigParser()
if os.path.isfile("etc/zoom-ingest/settings.ini"):
config.read("etc/zoom-ingest/settings.ini")
logger.debug("Configuration read from etc/zoom-ingest/settings.ini")
else:
config.read("/etc/zoom-ingest/settings.ini")
logger.debug("Configuration read from /etc/zoom-ingest/settings.ini")
except FileNotFoundError:
sys.exit("No settings found")
try:
enable_email = config.getboolean("Email", "enabled")
except (NoSectionError, NoOptionError):
logger.warn("Email configuration section and/or key is missing! Emails disabled by default")
enable_email = False
zingest.db.init(config)
z = Zoom(config)
r = Rabbit(config, z)
o = Opencast(config, r, z, enable_email)
def run_and_notify_about(thing):
while True:
try:
thing()
except Exception as e:
if enable_email:
email_logger = logging.getLogger("mail")
email_logger.exception("Zoom Uploader general error, will retry in 10 seconds after emailing...")
else:
logger.exception("Zoom Uploader general error, will retry in 10 seconds...")
time.sleep(10)
thread = threading.Thread(
target=run_and_notify_about(o.run),
daemon=True)
thread.start()
thread = threading.Thread(
target=run_and_notify_about(o.process_backlog),
daemon=True)
thread.start()
app = Flask(__name__)
@app.route('/', methods=['GET'])
def get_index():
return "Doc links, links to /count"
@app.route('/count', methods=['GET'])
def get_count():
return "Count of currently ingesting recordings is: "