incyclist-services 1.0.69 → 1.0.71
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/devices/ride/service.js +22 -14
- package/package.json +2 -2
|
@@ -476,6 +476,7 @@ class DeviceRideService extends events_1.default {
|
|
|
476
476
|
const check = () => {
|
|
477
477
|
const tsNow = Date.now();
|
|
478
478
|
const isPaused = ai.adapter.isPaused();
|
|
479
|
+
const prevStatus = ai.dataStatus;
|
|
479
480
|
if (isPaused || !ai.tsLastData) {
|
|
480
481
|
ai.tsLastData = tsNow;
|
|
481
482
|
ai.dataStatus = 'green';
|
|
@@ -491,16 +492,16 @@ class DeviceRideService extends events_1.default {
|
|
|
491
492
|
if (ai.isHealthy && (isAmber || isRed)) {
|
|
492
493
|
ai.isHealthy = false;
|
|
493
494
|
this.logEvent({ message: 'device unhealthy', device: ai.adapter.getUniqueName(), udid: ai.udid });
|
|
494
|
-
const { enabledCapabilities } = this.getEnabledCapabilities(ai);
|
|
495
|
-
this.emit('unhealthy', ai.udid, ai.dataStatus, enabledCapabilities);
|
|
496
495
|
console.log('~~~~ health check: prepare reconnect');
|
|
497
496
|
this.prepareReconnect(ai);
|
|
498
497
|
}
|
|
499
498
|
else if (!ai.isHealthy && !isAmber && !isRed) {
|
|
500
|
-
const { enabledCapabilities } = this.getEnabledCapabilities(ai);
|
|
501
499
|
ai.isHealthy = true;
|
|
502
500
|
this.logEvent({ message: 'device healthy', device: ai.adapter.getUniqueName(), udid: ai.udid });
|
|
503
|
-
|
|
501
|
+
}
|
|
502
|
+
if (ai.dataStatus !== prevStatus) {
|
|
503
|
+
const { enabledCapabilities } = this.getEnabledCapabilities(ai);
|
|
504
|
+
this.emit('health', ai.udid, ai.dataStatus, enabledCapabilities);
|
|
504
505
|
}
|
|
505
506
|
};
|
|
506
507
|
ai.ivToCheck = (0, timers_1.setInterval)(check, 1000);
|
|
@@ -522,7 +523,6 @@ class DeviceRideService extends events_1.default {
|
|
|
522
523
|
if (unhealthy.isHealthy || unhealthy.isRestarting)
|
|
523
524
|
return;
|
|
524
525
|
console.log('~~~~ health check: still unhealthy', unhealthy.udid, unhealthy.isHealthy, unhealthy.isRestarting);
|
|
525
|
-
unhealthy.isRestarting = true;
|
|
526
526
|
const ifName = unhealthy.adapter.getInterface();
|
|
527
527
|
const adapters = this.getAdapterList().filter(ai => ai.adapter.getInterface() === ifName);
|
|
528
528
|
if (!adapters.find(ai => ai.isHealthy)) {
|
|
@@ -542,25 +542,22 @@ class DeviceRideService extends events_1.default {
|
|
|
542
542
|
this.once('stop-ride', () => { stopRequested = true; });
|
|
543
543
|
const i = incyclist_devices_1.InterfaceFactory.create(ifName);
|
|
544
544
|
try {
|
|
545
|
+
console.log('~~~~ health check: prepare stop Adapters', ifName);
|
|
545
546
|
const promisesStop = [];
|
|
546
547
|
adapters.map(ai => {
|
|
547
|
-
|
|
548
|
-
promisesStop.push(this.stopAfterRestart(ai));
|
|
549
|
-
}
|
|
550
|
-
else {
|
|
551
|
-
promisesStop.push(ai.adapter.stop());
|
|
552
|
-
}
|
|
553
|
-
ai.isRestarting = true;
|
|
554
|
-
ai.adapter.off('data', this.deviceDataHandler);
|
|
548
|
+
promisesStop.push(this.stopAfterRestart(ai));
|
|
555
549
|
});
|
|
550
|
+
console.log('~~~~ health check: stop Adapters', ifName, promisesStop.length);
|
|
556
551
|
if (promisesStop.length > 0) {
|
|
557
552
|
yield Promise.allSettled(promisesStop);
|
|
558
553
|
}
|
|
554
|
+
console.log('~~~~ health check: reconnect interface', ifName);
|
|
559
555
|
if (!stopRequested) {
|
|
560
556
|
yield i.disconnect();
|
|
561
557
|
yield (0, sleep_1.sleep)(1000);
|
|
562
558
|
yield i.connect();
|
|
563
559
|
}
|
|
560
|
+
console.log('~~~~ health check: start adapters', ifName);
|
|
564
561
|
if (!stopRequested) {
|
|
565
562
|
const promisesStart = [];
|
|
566
563
|
adapters.map(ai => { promisesStart.push(ai.adapter.start()); });
|
|
@@ -571,12 +568,14 @@ class DeviceRideService extends events_1.default {
|
|
|
571
568
|
}
|
|
572
569
|
catch (err) {
|
|
573
570
|
this.logger.logEvent({ message: 'restart interface failed', interface: ifName, reason: err.message });
|
|
571
|
+
console.log('~~~~ health check: restart interface error', ifName, err);
|
|
574
572
|
}
|
|
575
573
|
adapters.map(ai => {
|
|
576
574
|
if (ai.adapter.isStarted()) {
|
|
577
575
|
ai.tsLastData = Date.now();
|
|
578
576
|
}
|
|
579
577
|
else {
|
|
578
|
+
console.log('~~~~ health check: adapter still not healthy', ifName, ai.udid);
|
|
580
579
|
ai.isRestarting = false;
|
|
581
580
|
this.prepareReconnect(ai);
|
|
582
581
|
}
|
|
@@ -588,18 +587,27 @@ class DeviceRideService extends events_1.default {
|
|
|
588
587
|
stopAfterRestart(unhealthy) {
|
|
589
588
|
return __awaiter(this, void 0, void 0, function* () {
|
|
590
589
|
if (unhealthy.isRestarting) {
|
|
590
|
+
console.log('~~~ health adapter lready stopping', unhealthy.udid);
|
|
591
591
|
yield new Promise(done => {
|
|
592
|
+
const to = setTimeout(done, 65000);
|
|
592
593
|
this.once('stop-adapter-confirmed', (udid) => {
|
|
593
|
-
if (udid === unhealthy.udid)
|
|
594
|
+
if (udid === unhealthy.udid) {
|
|
595
|
+
console.log('~~~ health adapter now can be stopped', unhealthy.udid);
|
|
596
|
+
clearTimeout(to);
|
|
594
597
|
done();
|
|
598
|
+
}
|
|
595
599
|
});
|
|
596
600
|
});
|
|
597
601
|
}
|
|
602
|
+
unhealthy.isRestarting = true;
|
|
603
|
+
unhealthy.adapter.off('data', this.deviceDataHandler);
|
|
604
|
+
console.log('~~~ health stop adapter', unhealthy.udid);
|
|
598
605
|
yield unhealthy.adapter.stop();
|
|
599
606
|
});
|
|
600
607
|
}
|
|
601
608
|
reconnectSingle(unhealthy) {
|
|
602
609
|
return __awaiter(this, void 0, void 0, function* () {
|
|
610
|
+
unhealthy.isRestarting = true;
|
|
603
611
|
let stopRequested = false;
|
|
604
612
|
this.once('stop-ride', () => { stopRequested = true; });
|
|
605
613
|
this.once('stop-adapter', (udid) => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "incyclist-services",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.71",
|
|
4
4
|
"peerDependencies": {
|
|
5
5
|
"gd-eventlog": "^0.1.26"
|
|
6
6
|
},
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
},
|
|
40
40
|
"dependencies": {
|
|
41
41
|
"axios": "^1.6.1",
|
|
42
|
-
"incyclist-devices": "^2.1.
|
|
42
|
+
"incyclist-devices": "^2.1.30",
|
|
43
43
|
"uuid": "^9.0.0",
|
|
44
44
|
"xml2js": "^0.6.2"
|
|
45
45
|
}
|