mirror of
https://github.com/clearml/clearml-server
synced 2025-03-03 18:54:20 +00:00
Add fileserver default cache timeout for downloaded files
This commit is contained in:
parent
27352c5cb6
commit
82be1840b0
@ -1,4 +1,5 @@
|
|||||||
import logging
|
import logging
|
||||||
|
import os
|
||||||
from functools import reduce
|
from functools import reduce
|
||||||
from os import getenv
|
from os import getenv
|
||||||
from os.path import expandvars
|
from os.path import expandvars
|
||||||
@ -16,6 +17,9 @@ DEFAULT_EXTRA_CONFIG_PATH = "/opt/trains/config"
|
|||||||
EXTRA_CONFIG_PATH_ENV_KEY = "TRAINS_CONFIG_DIR"
|
EXTRA_CONFIG_PATH_ENV_KEY = "TRAINS_CONFIG_DIR"
|
||||||
EXTRA_CONFIG_PATH_SEP = ":"
|
EXTRA_CONFIG_PATH_SEP = ":"
|
||||||
|
|
||||||
|
EXTRA_CONFIG_VALUES_ENV_KEY_SEP = "__"
|
||||||
|
EXTRA_CONFIG_VALUES_ENV_KEY_PREFIX = f"TRAINS{EXTRA_CONFIG_VALUES_ENV_KEY_SEP}"
|
||||||
|
|
||||||
|
|
||||||
class BasicConfig:
|
class BasicConfig:
|
||||||
NotSet = object()
|
NotSet = object()
|
||||||
@ -46,7 +50,23 @@ class BasicConfig:
|
|||||||
path = ".".join((self.prefix, Path(name).stem))
|
path = ".".join((self.prefix, Path(name).stem))
|
||||||
return logging.getLogger(path)
|
return logging.getLogger(path)
|
||||||
|
|
||||||
def _read_env_paths(self, key):
|
@staticmethod
|
||||||
|
def _read_extra_env_config_values():
|
||||||
|
""" Loads extra configuration from environment-injected values """
|
||||||
|
result = ConfigTree()
|
||||||
|
prefix = EXTRA_CONFIG_VALUES_ENV_KEY_PREFIX
|
||||||
|
|
||||||
|
keys = sorted(k for k in os.environ if k.startswith(prefix))
|
||||||
|
for key in keys:
|
||||||
|
path = key[len(prefix) :].replace(EXTRA_CONFIG_VALUES_ENV_KEY_SEP, ".").lower()
|
||||||
|
result = ConfigTree.merge_configs(
|
||||||
|
result, ConfigFactory.parse_string(f"{path}: {os.environ[key]}")
|
||||||
|
)
|
||||||
|
|
||||||
|
return result
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def _read_env_paths(key):
|
||||||
value = getenv(EXTRA_CONFIG_PATH_ENV_KEY, DEFAULT_EXTRA_CONFIG_PATH)
|
value = getenv(EXTRA_CONFIG_PATH_ENV_KEY, DEFAULT_EXTRA_CONFIG_PATH)
|
||||||
if value is None:
|
if value is None:
|
||||||
return
|
return
|
||||||
@ -64,12 +84,17 @@ class BasicConfig:
|
|||||||
|
|
||||||
def _load(self, verbose=True):
|
def _load(self, verbose=True):
|
||||||
extra_config_paths = self._read_env_paths(EXTRA_CONFIG_PATH_ENV_KEY) or []
|
extra_config_paths = self._read_env_paths(EXTRA_CONFIG_PATH_ENV_KEY) or []
|
||||||
|
extra_config_values = self._read_extra_env_config_values()
|
||||||
|
configs = [
|
||||||
|
self._read_recursive(path, verbose=verbose)
|
||||||
|
for path in [self.folder] + extra_config_paths
|
||||||
|
]
|
||||||
|
|
||||||
self._config = reduce(
|
self._config = reduce(
|
||||||
lambda config, path: ConfigTree.merge_configs(
|
lambda last, config: ConfigTree.merge_configs(
|
||||||
config, self._read_recursive(path, verbose=verbose), copy_trees=True
|
last, config, copy_trees=True
|
||||||
),
|
),
|
||||||
[self.folder] + extra_config_paths,
|
configs + [extra_config_values],
|
||||||
ConfigTree(),
|
ConfigTree(),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -1,6 +1,9 @@
|
|||||||
download {
|
download {
|
||||||
# Add response headers requesting no caching for served files
|
# Add response headers requesting no caching for served files
|
||||||
disable_browser_caching: false
|
disable_browser_caching: false
|
||||||
|
|
||||||
|
# Cache timeout to be set for downloaded files
|
||||||
|
cache_timeout_sec: 300
|
||||||
}
|
}
|
||||||
|
|
||||||
cors {
|
cors {
|
||||||
|
@ -17,6 +17,7 @@ CORS(app, **config.get("fileserver.cors"))
|
|||||||
Compress(app)
|
Compress(app)
|
||||||
|
|
||||||
app.config["UPLOAD_FOLDER"] = os.environ.get("TRAINS_UPLOAD_FOLDER") or DEFAULT_UPLOAD_FOLDER
|
app.config["UPLOAD_FOLDER"] = os.environ.get("TRAINS_UPLOAD_FOLDER") or DEFAULT_UPLOAD_FOLDER
|
||||||
|
app.config["SEND_FILE_MAX_AGE_DEFAULT"] = config.get("fileserver.download.cache_timeout_sec", 5 * 60)
|
||||||
|
|
||||||
|
|
||||||
@app.route("/", methods=["POST"])
|
@app.route("/", methods=["POST"])
|
||||||
|
Loading…
Reference in New Issue
Block a user