support-organizer/backend/fgo-request-manager/app.py
2023-11-24 20:50:18 +01:00

38 lines
937 B
Python

# pylint: disable=too-few-public-methods
from datetime import datetime
from flask import Flask
from flask_smorest import Api
from .config import APISettings
class IsSingletonException(Exception):
pass
class Application:
"""
This is a singleton that can be accessed using get_instance()
It has 2 properties
- app: Used for WSGI servers and such
- api: Used for Blueprints
"""
__instance = None
app = Flask(__name__)
app.config.from_object(APISettings)
api = None
alive_since = None
@staticmethod
def get_instance():
if Application.__instance is None:
Application()
return Application.__instance
def __init__(self):
if Application.__instance is not None:
raise IsSingletonException("This class is a singleton")
Application.__instance = self
self.api = Api(self.app)
self.alive_since = datetime.now()