0.4.0 allowed timeout to be set via environment and option

master
Kebler Network System Administrator 2021-03-10 10:17:02 -08:00
parent 77f3054c01
commit 468f560046
3 changed files with 18 additions and 11 deletions

View File

@ -2,7 +2,11 @@ import Watcher from '../src/watcher'
import onDeath from 'ondeath'
(async () => {
let options = {source:'./example/repo/**', ignored:['**/dontwatch.js'],ignoreList:['./example/repo/.gitignore']}
let options = {
source:'./example/repo/**',
ignored:['**/dontwatch.js'],
ignoreList:['./example/repo/.gitignore'],
readyTimeout:null}
// let options = {source:'./readme.md'}
// let options = {source:'./example/*'}

View File

@ -1,6 +1,6 @@
{
"name": "@uci-utils/watcher",
"version": "0.3.0",
"version": "0.4.0",
"description": "File System Watcher Class that emits events",
"main": "src/watcher.js",
"scripts": {
@ -30,15 +30,15 @@
},
"homepage": "https://github.com/uCOMmandIt/uci-utils#readme",
"dependencies": {
"@uci-utils/logger": "0.0.16",
"@uci-utils/logger": "0.0.18",
"@uci-utils/read-lines": "^0.2.2",
"chokidar": "^3.0.2"
"chokidar": "^3.5.1"
},
"devDependencies": {
"chai": "^4.2.0",
"chai": "^4.3.3",
"esm": "^3.2.25",
"mocha": "^6.2.0",
"nodemon": "^1.19.1",
"mocha": "^8.3.1",
"nodemon": "^2.0.7",
"ondeath": "^1.0.0"
}
}

View File

@ -9,7 +9,8 @@ import logger from '@uci-utils/logger'
let log = {}
const READY_TIMEOUT = 2000
const READY_TIMEOUT = 10000 //default
class Watcher extends Emitter {
constructor(opts={}) {
@ -17,6 +18,7 @@ class Watcher extends Emitter {
log = logger({ package:'@uci-utils/watcher', class:'Watcher', file:'src/watcher.js'})
opts.unlinkDir = Object.hasOwnProperty(opts.unlinkDir) ? opts.unlinkDir : true
this.opts = opts
this.timeout = process.env.READY_TIMEOUT || opts.readyTimeout || READY_TIMEOUT
this._ignored = []
this._ready=false
this.watching=false
@ -44,10 +46,11 @@ class Watcher extends Emitter {
this.opts = opts // save options
resolve()
})
log.debug(`initial scanning, timeout in ${this.timeout}ms`)
let readyTimeout = setTimeout(() =>{
log.fatal({options:opts, timeout:READY_TIMEOUT, msg:'Timeout: unable to complete initial scan'})
reject('timeout during intial scan')
},READY_TIMEOUT)
log.fatal({options:opts, timeout:this.timeout, msg:'Timeout: unable to complete initial scan'})
reject('timeout during initial scan')
},this.timeout)
}
else {
log.fatal('MUST provide a source directory(s) option to watch')