2019-12-08 22:43:49 +01:00
|
|
|
import argparse
|
2021-08-20 06:43:59 +02:00
|
|
|
from typing import Any, List
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
from bemani.backend.popn import PopnMusicFactory
|
|
|
|
from bemani.backend.jubeat import JubeatFactory
|
|
|
|
from bemani.backend.iidx import IIDXFactory
|
|
|
|
from bemani.backend.bishi import BishiBashiFactory
|
2021-09-04 17:17:22 +02:00
|
|
|
from bemani.backend.mga import MetalGearArcadeFactory
|
2019-12-08 22:43:49 +01:00
|
|
|
from bemani.backend.ddr import DDRFactory
|
|
|
|
from bemani.backend.sdvx import SoundVoltexFactory
|
|
|
|
from bemani.backend.reflec import ReflecBeatFactory
|
|
|
|
from bemani.backend.museca import MusecaFactory
|
|
|
|
from bemani.frontend.popn import PopnMusicCache
|
|
|
|
from bemani.frontend.iidx import IIDXCache
|
|
|
|
from bemani.frontend.jubeat import JubeatCache
|
|
|
|
from bemani.frontend.bishi import BishiBashiCache
|
2021-09-04 17:17:22 +02:00
|
|
|
from bemani.frontend.mga import MetalGearArcadeCache
|
2019-12-08 22:43:49 +01:00
|
|
|
from bemani.frontend.ddr import DDRCache
|
|
|
|
from bemani.frontend.sdvx import SoundVoltexCache
|
|
|
|
from bemani.frontend.reflec import ReflecBeatCache
|
|
|
|
from bemani.frontend.museca import MusecaCache
|
2020-05-08 20:22:31 +02:00
|
|
|
from bemani.common import GameConstants, Time
|
2021-08-20 06:43:59 +02:00
|
|
|
from bemani.data import Config, Data
|
2021-08-19 21:25:10 +02:00
|
|
|
from bemani.utils.config import load_config
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
|
2021-08-20 06:43:59 +02:00
|
|
|
def run_scheduled_work(config: Config) -> None:
|
2019-12-08 22:43:49 +01:00
|
|
|
data = Data(config)
|
|
|
|
|
|
|
|
# Only run scheduled work for enabled components
|
|
|
|
enabled_factories: List[Any] = []
|
|
|
|
enabled_caches: List[Any] = []
|
2021-08-20 06:43:59 +02:00
|
|
|
if GameConstants.IIDX in config.support:
|
2019-12-08 22:43:49 +01:00
|
|
|
enabled_factories.append(IIDXFactory)
|
|
|
|
enabled_caches.append(IIDXCache)
|
2021-08-20 06:43:59 +02:00
|
|
|
if GameConstants.POPN_MUSIC in config.support:
|
2019-12-08 22:43:49 +01:00
|
|
|
enabled_factories.append(PopnMusicFactory)
|
|
|
|
enabled_caches.append(PopnMusicCache)
|
2021-08-20 06:43:59 +02:00
|
|
|
if GameConstants.JUBEAT in config.support:
|
2019-12-08 22:43:49 +01:00
|
|
|
enabled_factories.append(JubeatFactory)
|
|
|
|
enabled_caches.append(JubeatCache)
|
2021-08-20 06:43:59 +02:00
|
|
|
if GameConstants.BISHI_BASHI in config.support:
|
2019-12-08 22:43:49 +01:00
|
|
|
enabled_factories.append(BishiBashiFactory)
|
|
|
|
enabled_caches.append(BishiBashiCache)
|
2021-09-04 17:17:22 +02:00
|
|
|
if GameConstants.MGA in config.support:
|
|
|
|
enabled_factories.append(MetalGearArcadeFactory)
|
|
|
|
enabled_caches.append(MetalGearArcadeCache)
|
2021-08-20 06:43:59 +02:00
|
|
|
if GameConstants.DDR in config.support:
|
2019-12-08 22:43:49 +01:00
|
|
|
enabled_factories.append(DDRFactory)
|
|
|
|
enabled_caches.append(DDRCache)
|
2021-08-20 06:43:59 +02:00
|
|
|
if GameConstants.SDVX in config.support:
|
2019-12-08 22:43:49 +01:00
|
|
|
enabled_factories.append(SoundVoltexFactory)
|
|
|
|
enabled_caches.append(SoundVoltexCache)
|
2021-08-20 06:43:59 +02:00
|
|
|
if GameConstants.REFLEC_BEAT in config.support:
|
2019-12-08 22:43:49 +01:00
|
|
|
enabled_factories.append(ReflecBeatFactory)
|
|
|
|
enabled_caches.append(ReflecBeatCache)
|
2021-08-20 06:43:59 +02:00
|
|
|
if GameConstants.MUSECA in config.support:
|
2019-12-08 22:43:49 +01:00
|
|
|
enabled_factories.append(MusecaFactory)
|
|
|
|
enabled_caches.append(MusecaCache)
|
|
|
|
|
|
|
|
# First, run any backend scheduled work
|
|
|
|
for factory in enabled_factories:
|
2021-05-31 20:07:03 +02:00
|
|
|
factory.run_scheduled_work(data, config)
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
# Now, warm the caches for the frontend
|
|
|
|
for cache in enabled_caches:
|
2021-05-31 20:07:03 +02:00
|
|
|
cache.preload(data, config)
|
2019-12-08 22:43:49 +01:00
|
|
|
|
2020-05-08 20:22:31 +02:00
|
|
|
# Now, possibly delete old log entries
|
|
|
|
keep_duration = config.get('event_log_duration', 0)
|
|
|
|
if keep_duration > 0:
|
|
|
|
# Calculate timestamp of events we should delete
|
|
|
|
oldest_event = Time.now() - keep_duration
|
|
|
|
data.local.network.delete_events(oldest_event)
|
|
|
|
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
parser = argparse.ArgumentParser(description="A scheduler for work that needs to be done periodically.")
|
|
|
|
parser.add_argument("-c", "--config", help="Core configuration. Defaults to server.yaml", type=str, default="server.yaml")
|
2021-08-20 21:37:26 +02:00
|
|
|
parser.add_argument("-o", "--read-only", action="store_true", help="Force the database into read-only mode.")
|
2019-12-08 22:43:49 +01:00
|
|
|
args = parser.parse_args()
|
|
|
|
|
|
|
|
# Set up global configuration
|
2021-08-20 06:43:59 +02:00
|
|
|
config = Config()
|
2021-08-19 21:25:10 +02:00
|
|
|
load_config(args.config, config)
|
2021-08-20 21:37:26 +02:00
|
|
|
if args.read_only:
|
|
|
|
config['database']['read_only'] = True
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
# Run out of band work
|
|
|
|
run_scheduled_work(config)
|