-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
64 lines (51 loc) · 1.9 KB
/
main.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
import sys
from apscheduler.schedulers.blocking import BlockingScheduler
from apscheduler.triggers.interval import IntervalTrigger
from core.env import EnvConfig, load_env
from core.live_stream_monitor import LiveStreamMonitor
from core.logger import setup_logger
class LiveStreamScheduler:
def __init__(self, env: EnvConfig, logger):
self.logger = logger
self.logger.info("Starting live stream monitoring system")
self.env = env
self.monitor = LiveStreamMonitor(self.env.auth_token, self.env.user_oid)
self.scheduler = BlockingScheduler()
def check_and_download(self):
"""Execute check and download task"""
try:
self.monitor.check_live_streams_and_start_download()
except Exception as e:
self.logger.error(f"Error while checking live streams: {str(e)}")
def start(self):
try:
self.scheduler.add_job(
self.check_and_download,
trigger=IntervalTrigger(seconds=self.env.interval),
name="check_livestreams",
)
self.check_and_download()
self.logger.info(
f"Scheduler started, checking every {self.env.interval} seconds"
)
self.scheduler.start()
except KeyboardInterrupt:
self.logger.info("Monitoring system manually stopped")
except Exception as e:
self.logger.error(f"System runtime error: {str(e)}")
raise
def main():
logger = setup_logger("Main")
try:
env = load_env()
except Exception as e:
logger.error(f"Environment configuration error: {str(e)}")
sys.exit(1)
try:
scheduler = LiveStreamScheduler(env=env, logger=logger)
scheduler.start()
except Exception as e:
logger.error(f"Scheduler error: {str(e)}")
sys.exit(1)
if __name__ == "__main__":
main()