Rename flask launchers -> _dev, _prod.

I want to reduce some complexity around here, part of which is that
launch imported entrypoint imported backend, all to do some proxy
wrapping which isn't necessary for the dev case anyway. Less
layers of wrapping and importing is good. Plus I think this naming
is more clear.
Additionally, I realized that the entrypoint aka prod launcher was
never updated to init the ycdldb as that was only done by the argparse
launcher. Now it's hardcoded and I'll consider adding a config file.
master
voussoir 2020-09-30 15:03:29 -07:00
parent f77809e793
commit 038ce9cffb
3 changed files with 31 additions and 19 deletions

View File

@ -2,7 +2,7 @@
This file is the gevent launcher for local / development use. This file is the gevent launcher for local / development use.
Simply run it on the command line: Simply run it on the command line:
python ycdl_flask_launch.py [port] python ycdl_flask_dev.py [port]
''' '''
import gevent.monkey; gevent.monkey.patch_all() import gevent.monkey; gevent.monkey.patch_all()
@ -22,7 +22,11 @@ from voussoirkit import pathclass
import bot import bot
import ycdl import ycdl
import ycdl_flask_entrypoint import backend
####################################################################################################
site = backend.site
HTTPS_DIR = pathclass.Path(__file__).parent.with_child('https') HTTPS_DIR = pathclass.Path(__file__).parent.with_child('https')
@ -33,21 +37,21 @@ def ycdl_flask_launch(create, port, refresh_rate, use_https):
if use_https: if use_https:
http = gevent.pywsgi.WSGIServer( http = gevent.pywsgi.WSGIServer(
listener=('0.0.0.0', port), listener=('0.0.0.0', port),
application=ycdl_flask_entrypoint.site, application=site,
keyfile=HTTPS_DIR.with_child('ycdl.key').absolute_path, keyfile=HTTPS_DIR.with_child('ycdl.key').absolute_path,
certfile=HTTPS_DIR.with_child('ycdl.crt').absolute_path, certfile=HTTPS_DIR.with_child('ycdl.crt').absolute_path,
) )
else: else:
http = gevent.pywsgi.WSGIServer( http = gevent.pywsgi.WSGIServer(
listener=('0.0.0.0', port), listener=('0.0.0.0', port),
application=ycdl_flask_entrypoint.site, application=site,
) )
youtube_core = ycdl.ytapi.Youtube(bot.get_youtube_key()) youtube_core = ycdl.ytapi.Youtube(bot.get_youtube_key())
ycdl_flask_entrypoint.backend.common.init_ycdldb(youtube_core, create=create) backend.common.init_ycdldb(youtube_core, create=create)
if refresh_rate is not None: if refresh_rate is not None:
ycdl_flask_entrypoint.backend.common.start_refresher_thread(refresh_rate) backend.common.start_refresher_thread(refresh_rate)
message = f'Starting server on port {port}' message = f'Starting server on port {port}'
if use_https: if use_https:

View File

@ -1,13 +0,0 @@
'''
This file is the WSGI entrypoint for remote / production use.
If you are using Gunicorn, for example:
gunicorn ycdl_flask_entrypoint:site --bind "0.0.0.0:PORT" --access-logfile "-"
'''
import werkzeug.middleware.proxy_fix
import backend
backend.site.wsgi_app = werkzeug.middleware.proxy_fix.ProxyFix(backend.site.wsgi_app)
site = backend.site

View File

@ -0,0 +1,21 @@
'''
This file is the WSGI entrypoint for remote / production use.
If you are using Gunicorn, for example:
gunicorn ycdl_flask_prod:site --bind "0.0.0.0:PORT" --access-logfile "-"
'''
import werkzeug.middleware.proxy_fix
import bot
import ycdl
import backend
backend.site.wsgi_app = werkzeug.middleware.proxy_fix.ProxyFix(backend.site.wsgi_app)
site = backend.site
# NOTE: Consider adding a local .json config file.
youtube_core = ycdl.ytapi.Youtube(bot.get_youtube_key())
backend.common.init_ycdldb(youtube_core, create=False)
backend.common.start_refresher_thread(86400)