Skip to content

Commit

Permalink
Trying something else.
Browse files Browse the repository at this point in the history
  • Loading branch information
sondregronas committed Jul 26, 2024
1 parent 9125383 commit b36a640
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 29 deletions.
31 changes: 2 additions & 29 deletions BookingSystem/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,39 +129,12 @@ def debug_login() -> flask.Response:

init_db()
Settings.verify_settings_exist()
start_routine()

return app


_app = create_app()
# We need to create an app object for gunicorn to use with the routine tasks only running on the main thread, not the
# workers. But since gunicorn doesn't run on Windows we need to catch the exception and run the app normally
try:
import gunicorn.app.base


class App(gunicorn.app.base.BaseApplication):
def __init__(self, app=None, options=None):
start_routine()
self.options = options or {}
self.application = _app
super().__init__()

def load_config(self):
config = {key: value for key, value in self.options.items()
if key in self.cfg.settings and value is not None}
for key, value in config.items():
self.cfg.set(key.lower(), value)

def load(self):
return self.application


app = App
except Exception as e:
logger.error(e)
start_routine()
app = _app
app = create_app()

if __name__ == '__main__':
app.run(host='0.0.0.0')
3 changes: 3 additions & 0 deletions BookingSystem/routine_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ def start_routine():
logger.info("Skipping routine tasks in testing environment")
return

if os.getpid() != int(os.getenv('GUNICORN_PID')):
return

def _task(job_func):
try:
job_func()
Expand Down

0 comments on commit b36a640

Please sign in to comment.