-
Notifications
You must be signed in to change notification settings - Fork 0
/
run_app.py
55 lines (44 loc) · 1.37 KB
/
run_app.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
from threading import Thread
import cherrypy
from django.core.wsgi import get_wsgi_application
from conf import settings
from manage import main as manage_py
from scheduler.scheduler import cron_worker
from tbot.bot import run_bot
def production_ready():
app = get_wsgi_application() # django_app
cherrypy.config.update(
{
"server.socket_host": "0.0.0.0",
"server.socket_port": settings.WEB_APP_PORT,
"server.thread_pool": 1,
"engine.autoreload.on": False,
"checker.on": False,
"tools.log_headers.on": False,
"request.show_tracebacks": False,
"request.show_mismatched_params": False,
"log.screen": False,
}
)
cherrypy.tree.graft(app, "/")
cherrypy.engine.start()
print("Started!")
cherrypy.engine.block()
if __name__ == "__main__":
manage_py("migrate")
manage_py("cleanup_temp")
print("Starting service...")
if settings.USE_BOT:
bot_thread = Thread(target=run_bot, daemon=True)
bot_thread.start()
schedule_tread = Thread(target=cron_worker, daemon=True)
schedule_tread.start()
if settings.DEBUG:
manage_py(
"runserver",
f"0.0.0.0:{settings.WEB_APP_PORT}",
"--nothreading",
"--noreload",
)
else:
production_ready()