forked from Josh5/TVH-IPTV-Config
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun.py
70 lines (52 loc) · 2.15 KB
/
run.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
#!/usr/bin/env python3
# -*- coding:utf-8 -*-
import os
from flask_migrate import Migrate
from flask_minify import Minify
from sys import exit
from backend.api.tasks import scheduler, update_playlists, map_new_tvh_services, update_epgs, rebuild_custom_epg, \
update_tvh_muxes, configure_tvh_with_defaults, update_tvh_channels
from lib.config import config_dict
from backend import create_app, db
# WARNING: Don't run with debug turned on in production!
DEBUG = (os.getenv('FLASK_DEBUG', 'False').capitalize() == 'True')
# The configuration
get_config_mode = 'Debug' if DEBUG else 'Production'
try:
# Load the configuration using the default values
app_config = config_dict[get_config_mode.capitalize()]
except KeyError:
exit('Error: Invalid <config_mode>. Expected values [Debug, Production] ')
app = create_app(app_config)
Migrate(app, db)
if not DEBUG:
Minify(app=app, html=True, js=False, cssless=False)
if DEBUG:
app.logger.info('DEBUG = ' + str(DEBUG))
app.logger.info('DBMS = ' + app_config.SQLALCHEMY_DATABASE_URI)
app.logger.info('ASSETS_ROOT = ' + app_config.ASSETS_ROOT)
@scheduler.task('interval', id='do_5_mins', minutes=5, misfire_grace_time=60)
def every_5_mins():
print("Running 5 minute scheduled task 'do_5_mins'")
with app.app_context():
configure_tvh_with_defaults(app)
map_new_tvh_services(app)
@scheduler.task('interval', id='do_60_mins', minutes=60, misfire_grace_time=300)
def every_60_mins():
print("Running hourly scheduled task 'do_60_mins'")
with app.app_context():
update_tvh_channels(app)
update_tvh_muxes(app)
@scheduler.task('cron', id='do_job_twice_a_day', hour='0/12', minute=1, misfire_grace_time=900)
def every_12_hours():
print("Running noon/midnight scheduled task 'do_job_twice_a_day'")
with app.app_context():
update_playlists(app)
update_epgs(app)
@scheduler.task('cron', id='do_job_once_a_day', hour=0, minute=10, misfire_grace_time=900)
def every_24_hours():
print("Running midnight scheduled task 'do_job_once_a_day'")
with app.app_context():
rebuild_custom_epg(app)
if __name__ == "__main__":
app.run()