Skip to content

Commit

Permalink
Add a configurable timeout for cache reads
Browse files Browse the repository at this point in the history
Fixes #369
  • Loading branch information
bigdaz committed Aug 16, 2022
1 parent 25e9b4d commit 43abe83
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
4 changes: 4 additions & 0 deletions action.yml
Expand Up @@ -66,6 +66,10 @@ inputs:
description: When 'true', the action will not attempt to restore the Gradle User Home entries from other Jobs.
required: false
default: false
cache-read-timeout:
description: A timeout value in seconds for cache reads. Requests taking longer that this will be aborted.
required: true
default: 600
workflow-job-context:
description: Used to uniquely identify the current job invocation. Defaults to the matrix values for this job; this should not be overridden by users (INTERNAL).
required: false
Expand Down
9 changes: 8 additions & 1 deletion src/cache-utils.ts
Expand Up @@ -15,6 +15,7 @@ const JOB_CONTEXT_PARAMETER = 'workflow-job-context'
const CACHE_DISABLED_PARAMETER = 'cache-disabled'
const CACHE_READONLY_PARAMETER = 'cache-read-only'
const CACHE_WRITEONLY_PARAMETER = 'cache-write-only'
const CACHE_TIMEOUT_PARAMETER = 'cache-read-timeout'
const STRICT_CACHE_MATCH_PARAMETER = 'gradle-home-cache-strict-match'
const CACHE_DEBUG_VAR = 'GRADLE_BUILD_ACTION_CACHE_DEBUG_ENABLED'

Expand Down Expand Up @@ -43,6 +44,10 @@ export function isCacheDebuggingEnabled(): boolean {
return process.env[CACHE_DEBUG_VAR] ? true : false
}

function getCacheReadTimeoutMs(): number {
return parseInt(core.getInput(CACHE_TIMEOUT_PARAMETER)) * 1000
}

/**
* Represents a key used to restore a cache entry.
* The Github Actions cache will first try for an exact match on the key.
Expand Down Expand Up @@ -148,7 +153,9 @@ export async function restoreCache(
): Promise<cache.CacheEntry | undefined> {
listener.markRequested(cacheKey, cacheRestoreKeys)
try {
const restoredEntry = await cache.restoreCache(cachePath, cacheKey, cacheRestoreKeys)
const restoredEntry = await cache.restoreCache(cachePath, cacheKey, cacheRestoreKeys, {
segmentTimeoutInMs: getCacheReadTimeoutMs()
})
if (restoredEntry !== undefined) {
listener.markRestored(restoredEntry.key, restoredEntry.size)
}
Expand Down

0 comments on commit 43abe83

Please sign in to comment.