Skip to content

Commit

Permalink
Update docs.
Browse files Browse the repository at this point in the history
  • Loading branch information
milesj committed Apr 17, 2024
1 parent b388948 commit 2f01cad
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 22 deletions.
4 changes: 3 additions & 1 deletion crates/cli/src/commands/clean.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ pub struct CleanArgs {
pub async fn clean(args: ArgsRef<CleanArgs>, workspace: ResourceRef<Workspace>) {
let done = create_progress_bar(format!("Cleaning stale cache older than {}", args.lifetime));

let (files_deleted, bytes_saved) = workspace.cache_engine.clean_stale_cache(&args.lifetime)?;
let (files_deleted, bytes_saved) = workspace
.cache_engine
.clean_stale_cache(&args.lifetime, true)?;

done(
format!("Deleted {files_deleted} files and saved {bytes_saved} bytes"),
Expand Down
2 changes: 1 addition & 1 deletion crates/core/action-pipeline/src/subscribers/local_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ impl Subscriber for LocalCacheSubscriber {
if workspace.config.runner.auto_clean_cache {
workspace
.cache_engine
.clean_stale_cache(&workspace.config.runner.cache_lifetime)?;
.clean_stale_cache(&workspace.config.runner.cache_lifetime, false)?;
}
}
_ => {}
Expand Down
25 changes: 19 additions & 6 deletions nextgen/cache/src/cache_engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,20 +62,33 @@ impl CacheEngine {
self.cache(self.states_dir.join(path.as_ref()))
}

pub fn clean_stale_cache(&self, lifetime: &str) -> miette::Result<(usize, u64)> {
pub fn clean_stale_cache(&self, lifetime: &str, all: bool) -> miette::Result<(usize, u64)> {
let duration =
parse_duration(lifetime).map_err(|e| miette::miette!("Invalid lifetime: {e}"))?;

debug!(
"Cleaning up and deleting stale cache older than \"{}\"",
"Cleaning up and deleting stale cached artifacts older than \"{}\"",
lifetime
);

let stats = fs::remove_dir_stale_contents(&self.cache_dir, duration)?;
let deleted = stats.files_deleted;
let bytes = stats.bytes_saved;
let mut deleted = 0;
let mut bytes = 0;

debug!("Deleted {} files and saved {} bytes", deleted, bytes);
if all {
let stats = fs::remove_dir_stale_contents(&self.cache_dir, duration)?;
deleted += stats.files_deleted;
bytes += stats.bytes_saved;
} else {
let stats = fs::remove_dir_stale_contents(self.cache_dir.join("hashes"), duration)?;
deleted += stats.files_deleted;
bytes += stats.bytes_saved;

let stats = fs::remove_dir_stale_contents(self.cache_dir.join("outputs"), duration)?;
deleted += stats.files_deleted;
bytes += stats.bytes_saved;
}

debug!("Deleted {} artifacts and saved {} bytes", deleted, bytes);

Ok((deleted, bytes))
}
Expand Down
41 changes: 27 additions & 14 deletions website/docs/config/workspace.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -418,20 +418,7 @@ notifier:

<HeadingApiLink to="/api/types/interface/WorkspaceConfig#runner" />

Configures aspects of the action pipeline.

### `cacheLifetime`

<HeadingApiLink to="/api/types/interface/RunnerConfig#cacheLifetime" />

The maximum lifetime of cached artifacts before they're marked as stale and automatically removed by
the action pipeline. Defaults to "7 days". This field requires an integer and a timeframe unit that
can be [parsed as a duration](https://docs.rs/humantime/2.1.0/humantime/fn.parse_duration.html).

```yaml title=".moon/workspace.yml" {2}
runner:
cacheLifetime: '24 hours'
```
Configures aspects of task running and the action pipeline.

### `archivableTargets`

Expand All @@ -451,6 +438,32 @@ runner:
> This setting primarily exists for [remote caching](../guides/remote-cache) as it will create and
> persist tar archives located in `.moon/cache/outputs`.

### `autoCleanCache`<VersionLabel version="1.24.0" />

<HeadingApiLink to="/api/types/interface/RunnerConfig#autoCleanCache" />

Automatically cleans cached artifacts older than [`cacheLifetime`](#cachelifetime) from the cache
directory (`.moon/cache`) after every run. This is useful for keeping the cache directory lean.
Defaults to `true`.

```yaml title=".moon/workspace.yml" {2}
runner:
autoCleanCache: false
```

### `cacheLifetime`

<HeadingApiLink to="/api/types/interface/RunnerConfig#cacheLifetime" />

The maximum lifetime of cached artifacts before they're marked as stale and automatically removed by
the action pipeline. Defaults to "7 days". This field requires an integer and a timeframe unit that
can be [parsed as a duration](https://docs.rs/humantime/2.1.0/humantime/fn.parse_duration.html).

```yaml title=".moon/workspace.yml" {2}
runner:
cacheLifetime: '24 hours'
```

### `inheritColorsForPipedTasks`

<HeadingApiLink to="/api/types/interface/RunnerConfig#inheritColorsForPipedTasks" />
Expand Down

0 comments on commit 2f01cad

Please sign in to comment.