35 lines
1.2 KiB
Python
35 lines
1.2 KiB
Python
"""Development entrypoint (Flask dev server, port 5001).
|
|
|
|
For production use Gunicorn via `start:app` (see start.py and Dockerfile).
|
|
"""
|
|
import os
|
|
import sys
|
|
|
|
os.chdir(os.path.dirname(os.path.abspath(__file__)))
|
|
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
|
|
|
|
from backend.app import create_app
|
|
from backend.scheduler import start_scheduler, stop_scheduler, try_acquire_scheduler_lock
|
|
|
|
db_url = os.environ.get("DATABASE_URL",
|
|
"postgresql://iot:iot@localhost:5432/iot_dboard")
|
|
app = create_app(db_path=db_url)
|
|
|
|
if __name__ == "__main__":
|
|
DEBUG = os.environ.get("FLASK_DEBUG", "").lower() in ("1", "true", "yes")
|
|
|
|
# In debug mode the reloader re-imports this module; only the child process
|
|
# should start the scheduler (advisory lock keeps it single anyway).
|
|
is_reloader_child = os.environ.get("WERKZEUG_RUN_MAIN") == "true"
|
|
if not DEBUG or is_reloader_child:
|
|
if try_acquire_scheduler_lock(db_url):
|
|
start_scheduler(app)
|
|
|
|
try:
|
|
bind_host = os.environ.get("FLASK_BIND", "127.0.0.1")
|
|
app.run(host=bind_host, port=int(os.environ.get("FLASK_PORT", "5001")),
|
|
debug=DEBUG, threaded=True)
|
|
finally:
|
|
if not DEBUG or is_reloader_child:
|
|
stop_scheduler()
|