1
0
mirror of synced 2024-11-23 22:10:59 +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:
global config
base_instantiate_cache(app, config)
base_instantiate_cache(config, app)
def main() -> None:

View File

@ -1,6 +1,6 @@
import yaml
from flask import Flask
from typing import Set
from typing import Optional, Set
from bemani.backend.iidx import IIDXFactory
from bemani.backend.popn import PopnMusicFactory
@ -27,7 +27,11 @@ def load_config(filename: str, config: Config) -> None:
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
# supports but right now the only demand is for in-memory, filesystem and memcached.
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:
global config
base_instantiate_cache(app, config)
base_instantiate_cache(config, app)
def main() -> None:

View File

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

View File

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