Skip to content

Commit 46e828e

Browse files
Disable cache backup/restore if cloudcache is used (#4125)
Signed-off-by: Ben Sherman <[email protected]> Signed-off-by: Paolo Di Tommaso <[email protected]> Co-authored-by: Paolo Di Tommaso <[email protected]>
1 parent b14674d commit 46e828e

File tree

3 files changed

+35
-4
lines changed

3 files changed

+35
-4
lines changed

plugins/nf-tower/src/main/io/seqera/tower/plugin/CacheCommand.groovy

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,9 @@ class CacheCommand implements PluginAbstractExec {
4646

4747
protected void cacheBackup() {
4848
log.debug "Running Nextflow cache backup"
49-
new CacheManager(System.getenv()).saveCacheFiles()
49+
final manager = new CacheManager(System.getenv())
50+
manager.saveCacheFiles()
51+
manager.saveMiscFiles()
5052
}
5153

5254
protected void archiveLogs(Session sess) {

plugins/nf-tower/src/main/io/seqera/tower/plugin/CacheManager.groovy

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,10 @@ class CacheManager {
6565
if( !sessionUuid )
6666
throw new AbortOperationException("Missing target uuid - cache sync cannot be performed")
6767

68-
this.localCachePath = Paths.get(".nextflow/cache/${sessionUuid}")
68+
// ignore the `localCachePath` when the `NXF_CLOUDCACHE_PATH` variable is set because
69+
// the nextflow cache metadata is going to be managed (and stored) via the nf-cloudcache plugin
70+
if( !env.containsKey('NXF_CLOUDCACHE_PATH') )
71+
this.localCachePath = Paths.get(".nextflow/cache/${sessionUuid}")
6972

7073
if( env.NXF_OUT_FILE )
7174
localOutFile = Paths.get(env.NXF_OUT_FILE)
@@ -80,7 +83,7 @@ class CacheManager {
8083
}
8184

8285
protected void restoreCacheFiles() {
83-
if( !remoteWorkDir || !sessionUuid )
86+
if( !remoteWorkDir || !sessionUuid || !localCachePath )
8487
return
8588

8689
if(!Files.exists(remoteCachePath)) {
@@ -100,7 +103,7 @@ class CacheManager {
100103
}
101104

102105
protected void saveCacheFiles() {
103-
if( !remoteWorkDir || !sessionUuid )
106+
if( !remoteWorkDir || !sessionUuid || !localCachePath )
104107
return
105108

106109
if( !Files.exists(localCachePath) ) {
@@ -118,7 +121,9 @@ class CacheManager {
118121
catch (Throwable e) {
119122
log.warn "Failed to backup resume metadata to remote store path: ${remoteCachePath.toUriString()} — cause: ${e}", e
120123
}
124+
}
121125

126+
protected void saveMiscFiles() {
122127
// — upload out file
123128
try {
124129
if( localOutFile?.exists() )

plugins/nf-tower/src/test/io/seqera/tower/plugin/CacheManagerTest.groovy

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ class CacheManagerTest extends Specification {
7878
tower.localCachePath.resolve('db/yyy').text = 'data yyy'
7979
and:
8080
tower.saveCacheFiles()
81+
tower.saveMiscFiles()
8182
then:
8283
tower.remoteCachePath.resolve('index-foo').text == 'index foo'
8384
tower.remoteCachePath.resolve('db/xxx').text == 'data xxx'
@@ -99,6 +100,7 @@ class CacheManagerTest extends Specification {
99100
tower.localCachePath.resolve('db/delta').text = 'data delta'
100101
and:
101102
tower.saveCacheFiles()
103+
tower.saveMiscFiles()
102104
then:
103105
tower.remoteCachePath.resolve('index-bar').text == 'index bar'
104106
tower.remoteCachePath.resolve('db/alpha').text == 'data alpha'
@@ -154,4 +156,26 @@ class CacheManagerTest extends Specification {
154156
cleanup:
155157
folder?.deleteDir()
156158
}
159+
160+
def 'should not backup/restore cache if cloudcache is enabled' () {
161+
given:
162+
def ENV = [
163+
NXF_UUID: 'uuid',
164+
NXF_WORK: '/work',
165+
NXF_CLOUDCACHE_PATH: 's3://my-bucket/cache'
166+
]
167+
and:
168+
def tower = new CacheManager(ENV)
169+
170+
when:
171+
tower.saveCacheFiles()
172+
then:
173+
0 * tower.getRemoteCachePath()
174+
175+
when:
176+
tower.restoreCacheFiles()
177+
then:
178+
0 * tower.getRemoteCachePath()
179+
180+
}
157181
}

0 commit comments

Comments
 (0)