-
Notifications
You must be signed in to change notification settings - Fork 595
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This commit refactor the httpfs configuration moving it into a indipendent class. This is needed to prevent a cyclic file system error when embedding nextflow library into another project. Signed-off-by: Paolo Di Tommaso <paolo.ditommaso@gmail.com>
- Loading branch information
1 parent
a6b7fa3
commit 445218a
Showing
4 changed files
with
102 additions
and
62 deletions.
There are no files selected for viewing
54 changes: 54 additions & 0 deletions
54
modules/nf-httpfs/src/main/nextflow/file/http/XFileSystemConfig.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package nextflow.file.http | ||
|
||
import groovy.transform.CompileStatic | ||
import nextflow.SysEnv | ||
|
||
/** | ||
* Hold HTTP/FTP virtual file system configuration | ||
* | ||
* @author Paolo Di Tommaso <paolo.ditommaso@gmail.com> | ||
*/ | ||
@CompileStatic | ||
class XFileSystemConfig { | ||
|
||
static XFileSystemConfig instance = new XFileSystemConfig() | ||
|
||
static final public String DEFAULT_RETRY_CODES = '404,410' | ||
|
||
static final public int MAX_REDIRECT_HOPS = 5 | ||
|
||
static final public int DEFAULT_BACK_OFF_BASE = 3 | ||
|
||
static final public int DEFAULT_BACK_OFF_DELAY = 250 | ||
|
||
static final public int DEFAULT_MAX_ATTEMPTS = 3 | ||
|
||
private int maxAttempts = DEFAULT_MAX_ATTEMPTS | ||
|
||
private int backOffBase = DEFAULT_BACK_OFF_BASE | ||
|
||
private int backOffDelay = DEFAULT_BACK_OFF_DELAY | ||
|
||
private List<Integer> retryCodes | ||
|
||
{ | ||
maxAttempts = config('NXF_HTTPFS_MAX_ATTEMPTS', DEFAULT_MAX_ATTEMPTS) as Integer | ||
backOffBase = config('NXF_HTTPFS_BACKOFF_BASE', DEFAULT_BACK_OFF_BASE) as Integer | ||
backOffDelay = config('NXF_HTTPFS_DELAY', DEFAULT_BACK_OFF_DELAY) as Integer | ||
retryCodes = config('NXF_HTTPFS_RETRY_CODES', DEFAULT_RETRY_CODES).tokenize(',').collect( val -> val as Integer ) | ||
} | ||
|
||
static String config(String name, def defValue) { | ||
return SysEnv.containsKey(name) ? SysEnv.get(name) : defValue.toString() | ||
} | ||
|
||
int maxAttempts() { maxAttempts } | ||
|
||
int backOffBase() { backOffBase } | ||
|
||
int backOffDelay() { backOffDelay } | ||
|
||
List<Integer> retryCodes() { retryCodes } | ||
|
||
static XFileSystemConfig config() { return instance } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
modules/nf-httpfs/src/test/nextflow/file/http/XFileSystemConfigTest.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package nextflow.file.http | ||
|
||
import spock.lang.Specification | ||
|
||
import nextflow.SysEnv | ||
|
||
/** | ||
* | ||
* @author Paolo Di Tommaso <paolo.ditommaso@gmail.com> | ||
*/ | ||
class XFileSystemConfigTest extends Specification { | ||
|
||
def 'should create with default config settings' () { | ||
when: | ||
def config = new XFileSystemConfig() | ||
then: | ||
config.retryCodes() == XFileSystemConfig.DEFAULT_RETRY_CODES.tokenize(',').collect( it -> it as int ) | ||
config.backOffDelay() == XFileSystemConfig.DEFAULT_BACK_OFF_DELAY | ||
config.backOffBase() == XFileSystemConfig.DEFAULT_BACK_OFF_BASE | ||
config.maxAttempts() == XFileSystemConfig.DEFAULT_MAX_ATTEMPTS | ||
} | ||
|
||
def 'should create with custom config settings' () { | ||
given: | ||
SysEnv.push([NXF_HTTPFS_MAX_ATTEMPTS: '10', | ||
NXF_HTTPFS_BACKOFF_BASE: '300', | ||
NXF_HTTPFS_DELAY : '400', | ||
NXF_HTTPFS_RETRY_CODES : '1,2,3']) | ||
|
||
when: | ||
def config = new XFileSystemConfig() | ||
then: | ||
config.retryCodes() == [1,2,3] | ||
config.backOffDelay() == 400 | ||
config.backOffBase() == 300 | ||
config.maxAttempts() == 10 | ||
|
||
cleanup: | ||
SysEnv.pop() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters