Commit 295cdea0 authored by Jérome Perrin's avatar Jérome Perrin

better type to define the interval

Use https://www.npmjs.com/package/parse-duration which supports duration
units easier for humans
parent 4f931469
#!/usr/bin/env zx #!/usr/bin/env zx
import 'zx/globals' import 'zx/globals'
import {default as parseDuration} from 'parse-duration'
const configData = await fs.readFile(argv['config'] || './config.yaml', 'utf-8') const configData = await fs.readFile(argv['config'] || './config.yaml', 'utf-8')
const config = YAML.parse(configData) const config = YAML.parse(configData)
const wd = config['working-directory'] || 'work'; const wd = config['working-directory'] || 'work';
const interval = (config.interval || (15 * 60)) * 1000; const interval = parseDuration(config.interval || '15m', 'ms')
if (!fs.existsSync(wd)) { if (!fs.existsSync(wd)) {
echo(`Initializing ${wd}`) echo(`Initializing ${wd}`)
......
...@@ -10,7 +10,7 @@ project: ...@@ -10,7 +10,7 @@ project:
url: https://lab.nexedi.com/nexedi/erp5/ url: https://lab.nexedi.com/nexedi/erp5/
branch: zope4py2 branch: zope4py2
interval: 2 interval: 10h
# optional: committer for the merge commits # optional: committer for the merge commits
committer: committer:
......
...@@ -101,9 +101,15 @@ ...@@ -101,9 +101,15 @@
} }
}, },
"interval": { "interval": {
"type": "number", "type": "string",
"description": "Interval in seconds between each fetch", "description": "Interval between each fetch",
"default": 900 "default": "15m",
"examples": [
"10m",
"3h",
"1d",
"1w"
]
} }
} }
} }
\ No newline at end of file
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
"packages": { "packages": {
"": { "": {
"devDependencies": { "devDependencies": {
"parse-duration": "^1.0.2",
"zx": "^7.0.6" "zx": "^7.0.6"
} }
}, },
...@@ -399,6 +400,12 @@ ...@@ -399,6 +400,12 @@
"url": "https://opencollective.com/node-fetch" "url": "https://opencollective.com/node-fetch"
} }
}, },
"node_modules/parse-duration": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/parse-duration/-/parse-duration-1.0.2.tgz",
"integrity": "sha512-Dg27N6mfok+ow1a2rj/nRjtCfaKrHUZV2SJpEn/s8GaVUSlf4GGRCRP1c13Hj+wfPKVMrFDqLMLITkYKgKxyyg==",
"dev": true
},
"node_modules/path-type": { "node_modules/path-type": {
"version": "4.0.0", "version": "4.0.0",
"resolved": "https://registry.npmjs.org/path-type/-/path-type-4.0.0.tgz", "resolved": "https://registry.npmjs.org/path-type/-/path-type-4.0.0.tgz",
...@@ -912,6 +919,12 @@ ...@@ -912,6 +919,12 @@
"formdata-polyfill": "^4.0.10" "formdata-polyfill": "^4.0.10"
} }
}, },
"parse-duration": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/parse-duration/-/parse-duration-1.0.2.tgz",
"integrity": "sha512-Dg27N6mfok+ow1a2rj/nRjtCfaKrHUZV2SJpEn/s8GaVUSlf4GGRCRP1c13Hj+wfPKVMrFDqLMLITkYKgKxyyg==",
"dev": true
},
"path-type": { "path-type": {
"version": "4.0.0", "version": "4.0.0",
"resolved": "https://registry.npmjs.org/path-type/-/path-type-4.0.0.tgz", "resolved": "https://registry.npmjs.org/path-type/-/path-type-4.0.0.tgz",
......
{ {
"devDependencies": { "devDependencies": {
"parse-duration": "^1.0.2",
"zx": "^7.0.6" "zx": "^7.0.6"
} }
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment