diff --git a/optuna_dashboard/app.py b/optuna_dashboard/app.py index fdfe1039..e1af9ca9 100644 --- a/optuna_dashboard/app.py +++ b/optuna_dashboard/app.py @@ -9,7 +9,7 @@ from typing import Union, Dict, List, Optional, TypeVar, Callable, Any, cast from bottle import Bottle, BaseResponse, redirect, request, response, static_file from optuna.exceptions import DuplicatedStudyError -from optuna.storages import BaseStorage, get_storage +from optuna.storages import BaseStorage from optuna.trial import FrozenTrial from optuna.study import StudyDirection, StudySummary @@ -84,7 +84,7 @@ def get_trials( if ( trials is not None and last_fetched_at is not None - and datetime.now() - last_fetched_at < timedelta(ttl_seconds) + and datetime.now() - last_fetched_at < timedelta(seconds=ttl_seconds) ): return trials trials = storage.get_all_trials(study_id) @@ -94,9 +94,8 @@ def get_trials( return trials -def create_app(storage_or_url: Union[str, BaseStorage]) -> Bottle: +def create_app(storage: BaseStorage) -> Bottle: app = Bottle() - storage = get_storage(storage_or_url) @app.hook("before_request") def remove_trailing_slashes_hook() -> None: diff --git a/optuna_dashboard/cli.py b/optuna_dashboard/cli.py index 931119a7..40d4ec67 100644 --- a/optuna_dashboard/cli.py +++ b/optuna_dashboard/cli.py @@ -2,6 +2,7 @@ import argparse import os from bottle import run +from optuna.storages import RDBStorage from .app import create_app from .version import __version__ @@ -23,7 +24,8 @@ def main() -> None: parser.add_argument("--quiet", "-q", help="quiet", action="store_true") args = parser.parse_args() - app = create_app(args.storage) + storage = RDBStorage(args.storage) + app = create_app(storage) run(app, host=args.host, port=args.port, quiet=args.quiet, reloader=AUTO_RELOAD)