Class: Tebako::DeploymentCache
- Inherits:
-
Object
- Object
- Tebako::DeploymentCache
- Defined in:
- lib/tebako/deployment_cache.rb
Overview
Caches the complete post-deploy application tree by its effective inputs.
Constant Summary collapse
- SCHEMA_VERSION =
1- MANIFEST_NAME =
"manifest.json"- TREE_NAME =
"tree"- REFERENCE_DIR =
"references"
Instance Method Summary collapse
- #fetch(target_dir) ⇒ Object
-
#initialize(cache_dir:, project_root:, metadata:, excluded: [], implementation_root: nil, paths: ["."], stage: "deployment") ⇒ DeploymentCache
constructor
A new instance of DeploymentCache.
Constructor Details
#initialize(cache_dir:, project_root:, metadata:, excluded: [], implementation_root: nil, paths: ["."], stage: "deployment") ⇒ DeploymentCache
Returns a new instance of DeploymentCache.
26 27 28 29 30 31 32 33 34 35 |
# File 'lib/tebako/deployment_cache.rb', line 26 def initialize(cache_dir:, project_root:, metadata:, excluded: [], implementation_root: nil, paths: ["."], stage: "deployment") @cache_dir = File.(cache_dir) @project_root = File.(project_root) @metadata = stringify_and_sort() @excluded = excluded.compact.map { |path| File.(path) } @implementation_root = implementation_root || File.(__dir__) @paths = paths.sort @stage = stage end |
Instance Method Details
#fetch(target_dir) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/tebako/deployment_cache.rb', line 37 def fetch(target_dir) FileUtils.mkdir_p(@cache_dir) inputs = build_inputs key = digest_json(inputs) cache_path = File.join(@cache_dir, key) started_at = monotonic_time with_lock("#{cache_path}.lock") do if valid_entry?(cache_path, key) restore(cache_path, target_dir) report("reused", "all deployment inputs are unchanged", key, started_at) update_reference(inputs, key) return :hit end changed_inputs = changed_inputs_since_last_build(inputs) remove_invalid_entry(cache_path) yield save(cache_path, target_dir, key, inputs) update_reference(inputs, key) report("rebuilt", miss_reason(changed_inputs), key, started_at, changed_inputs) :miss end end |