def put(self, key: str, outputs: Env.Bindings[Value.Base]) -> None: if not self._cfg["call_cache"].get_bool("put"): return def cache(v: Union[Value.File, Value.Directory]) -> str: _cached_files[inode(v.value)] = (key, outputs) return "" with _uploaded_files_lock: Value.rewrite_env_paths(outputs, cache) cache_put(self._cfg, self._logger, key, outputs)
def cache_put(cfg: config.Loader, logger: logging.Logger, key: str, outputs: Env.Bindings[Value.Base]): if not (cfg["call_cache"].get_bool("put") and cfg["call_cache"]["backend"] == "s3_progressive_upload_call_cache_backend"): return missing = False def cache(v: Union[Value.File, Value.Directory]) -> str: nonlocal missing missing = missing or inode(str(v.value)) not in _uploaded_files if missing: return "" return _uploaded_files[inode(str(v.value))] remapped_outputs = Value.rewrite_env_paths(outputs, cache) if not missing and cfg.has_option("s3_progressive_upload", "uri_prefix"): uri = os.path.join(get_s3_put_prefix(cfg), "cache", f"{key}.json") s3_object(uri).put( Body=json.dumps(values_to_json(remapped_outputs)).encode()) flag_temporary(uri) logger.info(_("call cache insert", cache_file=uri))