1
0
mirror of synced 2024-11-30 16:54:30 +01:00

Centralize flask instantiation hack in one place for non-web utilities that still need production cache.

This commit is contained in:
Jennifer Taylor 2023-08-13 19:08:31 +00:00
parent 2491eb0767
commit a10350fb62
5 changed files with 11 additions and 8 deletions

View File

@ -15,7 +15,7 @@ def load_config(filename: str) -> None:
def instantiate_cache(app: Any) -> None: def instantiate_cache(app: Any) -> None:
global config global config
base_instantiate_cache(app, config) base_instantiate_cache(config, app)
def main() -> None: def main() -> None:

View File

@ -1,6 +1,6 @@
import yaml import yaml
from flask import Flask from flask import Flask
from typing import Set from typing import Optional, Set
from bemani.backend.iidx import IIDXFactory from bemani.backend.iidx import IIDXFactory
from bemani.backend.popn import PopnMusicFactory from bemani.backend.popn import PopnMusicFactory
@ -27,7 +27,11 @@ def load_config(filename: str, config: Config) -> None:
config["support"] = supported_series config["support"] = supported_series
def instantiate_cache(app: Flask, config: Config) -> None: def instantiate_cache(config: Config, app: Optional[Flask] = None) -> None:
# Possibly set up a dummy app context because flask-caching needs it.
if app is None:
app = Flask(__name__)
# This could easily be extended to add support for any other backend that flask-caching # This could easily be extended to add support for any other backend that flask-caching
# supports but right now the only demand is for in-memory, filesystem and memcached. # supports but right now the only demand is for in-memory, filesystem and memcached.
if config.memcached_server is not None: if config.memcached_server is not None:

View File

@ -64,7 +64,7 @@ def load_config(filename: str) -> None:
def instantiate_cache(app: Any) -> None: def instantiate_cache(app: Any) -> None:
global config global config
base_instantiate_cache(app, config) base_instantiate_cache(config, app)
def main() -> None: def main() -> None:

View File

@ -1,5 +1,4 @@
import argparse import argparse
from flask import Flask
from typing import Any, List from typing import Any, List
from bemani.backend.popn import PopnMusicFactory from bemani.backend.popn import PopnMusicFactory
@ -100,8 +99,8 @@ if __name__ == "__main__":
if args.read_only: if args.read_only:
config["database"]["read_only"] = True config["database"]["read_only"] = True
# Set up production cache, with a dummy app context because flask-caching needs it. # Set up production cache.
instantiate_cache(Flask(__name__), config) instantiate_cache(config)
# Run out of band work # Run out of band work
run_scheduled_work(config) run_scheduled_work(config)

View File

@ -130,7 +130,7 @@ def load_config(filename: str) -> None:
def instantiate_cache(app: Any) -> None: def instantiate_cache(app: Any) -> None:
global config global config
base_instantiate_cache(app, config) base_instantiate_cache(config, app)
if __name__ == "__main__": if __name__ == "__main__":