From 5f3a89345a8781371a3d07f74a167caec164f006 Mon Sep 17 00:00:00 2001 From: Taka Date: Wed, 8 May 2019 10:32:29 +0000 Subject: [PATCH] Changed when we download a fresh copy of the ROAR scenario index. --- vasl_templates/webapp/__init__.py | 10 ++++++---- vasl_templates/webapp/roar.py | 8 ++++++-- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/vasl_templates/webapp/__init__.py b/vasl_templates/webapp/__init__.py index 9f76c32..6897f6b 100644 --- a/vasl_templates/webapp/__init__.py +++ b/vasl_templates/webapp/__init__.py @@ -37,10 +37,6 @@ def _on_startup(): from vasl_templates.webapp.main import startup_msg_store #pylint: disable=cyclic-import load_vo_notes( startup_msg_store ) - # initialize ROAR integration - from vasl_templates.webapp.roar import init_roar #pylint: disable=cyclic-import - init_roar( startup_msg_store ) - # --------------------------------------------------------------------- def _load_config( fname, section ): @@ -108,5 +104,11 @@ if app.config.get( "ENABLE_REMOTE_TEST_CONTROL" ): # install our signal handler (must be done in the main thread) signal.signal( signal.SIGINT, _on_sigint ) +# initialize ROAR integration +# NOTE: We do this here, rather in _on_startup(), so that we can start downloading the latest scenario index file +# without having to wait for the first request (e.g. if we are running as a standalone server, not the desktop app). +from vasl_templates.webapp.roar import init_roar +init_roar() + # register startup initialization app.before_first_request( _on_startup ) diff --git a/vasl_templates/webapp/roar.py b/vasl_templates/webapp/roar.py index 5bbc59b..50894e2 100644 --- a/vasl_templates/webapp/roar.py +++ b/vasl_templates/webapp/roar.py @@ -24,9 +24,13 @@ CACHE_TTL = 6 * 60*60 # --------------------------------------------------------------------- -def init_roar( msg_store ): +def init_roar(): """Initialize ROAR integration.""" + # initialize + from vasl_templates.webapp.main import startup_msg_store + msg_store = startup_msg_store + # initialize download = True cache_fname = os.path.join( tempfile.gettempdir(), "vasl-templates.roar-scenario-index.json" ) @@ -45,7 +49,7 @@ def init_roar( msg_store ): age = int( time.time() - mtime ) _logger.debug( "Cached scenario index age: %s (ttl=%s) (mtime=%s)", datetime.timedelta(seconds=age), datetime.timedelta(seconds=CACHE_TTL), - time.strftime( "%Y-%m-%d %H:%M:%S", time.gmtime(mtime) ) + time.strftime( "%Y-%m-%d %H:%M:%S", time.localtime(mtime) ) ) if age < CACHE_TTL: download = False