Allow specifying polling delay on dirWatch

This commit is contained in:
Chrystian Huot 2020-08-23 10:14:55 -04:00
parent fff40747d2
commit d4f25eee3c
3 changed files with 74 additions and 60 deletions

View file

@ -6,6 +6,7 @@
- Fix potential error in handling keypadBeeps styles. - Fix potential error in handling keypadBeeps styles.
- Change handling of skip delay on client. - Change handling of skip delay on client.
- Fix beep method not completing promise in some situation. - Fix beep method not completing promise in some situation.
- Allow specifying polling delay on dirWatch
# Version 4.6 # Version 4.6

View file

@ -333,7 +333,7 @@ dirWatch: {
system?: number | string; // optional system?: number | string; // optional
talkgroup?: number | string; // optional talkgroup?: number | string; // optional
type?: "default" | "trunk-recorder"; // optional, default is default type?: "default" | "trunk-recorder"; // optional, default is default
usePolling?: boolean; // optional, default is false usePolling?: boolean | number; // optional, value is in ms, true = 1000ms, default is false
}[] }[]
``` ```
@ -356,6 +356,7 @@ dirWatch: {
* **system** - A valid system id defined in **rdioScanner.systems**. * **system** - A valid system id defined in **rdioScanner.systems**.
* **talkgroup** - A valid talkgroup id defined in **rdioScanner.systems**. * **talkgroup** - A valid talkgroup id defined in **rdioScanner.systems**.
* **type** - In case of *Trunk Recorder*, the metadata of the *JSON file* will be used. * **type** - In case of *Trunk Recorder*, the metadata of the *JSON file* will be used.
* **usePolling** - When monitoring a network folder, you must use Polling for dirWatch to work. However, this is very CPU intensive and should be used with care. You can also try values greater than 1000 to decrease CPU consumption.
> Note that [Rdio Scanner](https://github.com/chuot/rdio-scanner) must know the **system id** and the **talkgroup id** for the call to be ingested. These two values must be specified either by **dirWatch.system**, **dirWatch.talkgroup**, **dirWatch.mask** or a mix of them. **dirWatch.system** and **dirWatch.talkgroup** have priority over **dirWatch.mask**. > Note that [Rdio Scanner](https://github.com/chuot/rdio-scanner) must know the **system id** and the **talkgroup id** for the call to be ingested. These two values must be specified either by **dirWatch.system**, **dirWatch.talkgroup**, **dirWatch.mask** or a mix of them. **dirWatch.system** and **dirWatch.talkgroup** have priority over **dirWatch.mask**.
@ -382,7 +383,7 @@ Default value is an empty array `[]` .
"extension": "wav", "extension": "wav",
"system": 21, "system": 21,
"type": "trunk-recorder" "type": "trunk-recorder"
}, }
] ]
``` ```

View file

@ -36,7 +36,6 @@ class DirWatch {
this.registredDirectories = []; this.registredDirectories = [];
ctx.once('ready', () => {
this.config.forEach((dirWatch = {}) => { this.config.forEach((dirWatch = {}) => {
if (typeof dirWatch.directory !== 'string' || !dirWatch.directory.length) { if (typeof dirWatch.directory !== 'string' || !dirWatch.directory.length) {
console.error(`Config: No dirWatch.direction defined`); console.error(`Config: No dirWatch.direction defined`);
@ -66,7 +65,11 @@ class DirWatch {
delete dirWatch.mask; delete dirWatch.mask;
} }
if (typeof dirWatch.usePolling !== 'boolean' || !dirWatch.usePolling) { dirWatch.usePolling = dirWatch.usePolling === true ? true
: typeof dirWatch.usePolling === 'number' && dirWatch.usePolling >= 1000 ? dirWatch.usePolling
: false;
if (!dirWatch.usePolling) {
delete dirWatch.usePolling; delete dirWatch.usePolling;
} }
@ -92,13 +95,22 @@ class DirWatch {
} else { } else {
this.registredDirectories.push(dir); this.registredDirectories.push(dir);
} }
});
const watcher = chokidar.watch(dir, { ctx.once('ready', () => {
this.config.forEach((dirWatch = {}) => {
const options = {
awaitWriteFinish: true, awaitWriteFinish: true,
ignoreInitial: !dirWatch.deleteAfter, ignoreInitial: !dirWatch.deleteAfter,
recursive: true, recursive: true,
usePolling: dirWatch.usePolling, usePolling: !!dirWatch.usePolling || false,
}); };
if (options.usePolling) {
options.binaryInterval = options.interval = dirWatch.usePolling === true ? 1000 : dirWatch.usePolling;
}
const watcher = chokidar.watch(path.resolve(__dirname, '../../..', dirWatch.directory), options);
switch (dirWatch.type) { switch (dirWatch.type) {
case 'trunk-recorder': case 'trunk-recorder':