@phystack/device-phyos 6.15.2 → 6.15.3
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/dist/index.js +23 -0
- package/package.json +5 -5
package/dist/index.js
CHANGED
|
@@ -166,6 +166,7 @@ class DevicePhyos {
|
|
|
166
166
|
GRID_ENV;
|
|
167
167
|
PHYOS_VERSION;
|
|
168
168
|
firstConnect;
|
|
169
|
+
orphanSweepInFlight = false;
|
|
169
170
|
phyHubInterval;
|
|
170
171
|
logger;
|
|
171
172
|
scheduler = new scheduler_service_1.Scheduler();
|
|
@@ -247,6 +248,21 @@ class DevicePhyos {
|
|
|
247
248
|
this.logger.info('initializeCachedInstances(): No valid twins to initialize');
|
|
248
249
|
}
|
|
249
250
|
}
|
|
251
|
+
async sweepOrphanedContainers() {
|
|
252
|
+
if (this.orphanSweepInFlight) {
|
|
253
|
+
return;
|
|
254
|
+
}
|
|
255
|
+
this.orphanSweepInFlight = true;
|
|
256
|
+
try {
|
|
257
|
+
await instances_1.dockerManager.sweepOrphanedContainers(async () => {
|
|
258
|
+
const twinsByType = (await this.twinManager.getCachedTwins());
|
|
259
|
+
return Object.values(twinsByType).flat();
|
|
260
|
+
});
|
|
261
|
+
}
|
|
262
|
+
finally {
|
|
263
|
+
this.orphanSweepInFlight = false;
|
|
264
|
+
}
|
|
265
|
+
}
|
|
250
266
|
async connectPhyHub(hubDevice) {
|
|
251
267
|
this.twinManager = await (0, twin_manager_1.getTwinManagerInstance)();
|
|
252
268
|
this.twinManager.setHubDevice(hubDevice);
|
|
@@ -282,6 +298,7 @@ class DevicePhyos {
|
|
|
282
298
|
hubDevice.setTwinUpdateHandler(async (twin) => {
|
|
283
299
|
this.logger.info('connectPhyHub() on setTwinUpdateHandler(): Twin update received, updating instance...');
|
|
284
300
|
await this.twinManager.cacheHubTwin(twin);
|
|
301
|
+
instances_1.dockerManager.markTwinAlive(twin.id);
|
|
285
302
|
if (twin.type === 'Device' && twin.properties?.desired?.timezone) {
|
|
286
303
|
try {
|
|
287
304
|
const region = JSON.parse(fs_1.default.readFileSync(regionFilePath, 'utf8'));
|
|
@@ -357,6 +374,9 @@ class DevicePhyos {
|
|
|
357
374
|
if (twins?.length) {
|
|
358
375
|
this.logger.info('connectPhyHub(): Caching twins from server response...');
|
|
359
376
|
await Promise.all(twins.map((twin) => this.twinManager.cacheHubTwin(twin)));
|
|
377
|
+
for (const twin of twins) {
|
|
378
|
+
instances_1.dockerManager.markTwinAlive(twin.id);
|
|
379
|
+
}
|
|
360
380
|
this.logger.info(`connectPhyHub(): Cached ${twins.length} twins from hub`);
|
|
361
381
|
const twinsByType = (await this.twinManager.getCachedTwins());
|
|
362
382
|
const allTwinIds = Object.values(twinsByType).flat();
|
|
@@ -365,6 +385,9 @@ class DevicePhyos {
|
|
|
365
385
|
console.log(`connectPhyHub(): allTwins ${allTwins.length}`);
|
|
366
386
|
await (0, instances_1.initInstances)(this.twinManager, allTwins);
|
|
367
387
|
await (0, methods_1.initMethods)(hubDevice);
|
|
388
|
+
this.sweepOrphanedContainers().catch((error) => {
|
|
389
|
+
this.logger.error('connectPhyHub(): Failed to sweep orphaned containers', error);
|
|
390
|
+
});
|
|
368
391
|
}
|
|
369
392
|
});
|
|
370
393
|
await this.initializeCachedInstances(this.twinManager);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@phystack/device-phyos",
|
|
3
|
-
"version": "6.15.
|
|
3
|
+
"version": "6.15.3",
|
|
4
4
|
"description": "PhyOS device agent",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"license": "UNLICENSED",
|
|
@@ -25,9 +25,9 @@
|
|
|
25
25
|
"format": "prettier --write \"src/**/*.{ts,js,json,md}\""
|
|
26
26
|
},
|
|
27
27
|
"optionalDependencies": {
|
|
28
|
-
"@phystack/phydevice-darwin-arm64": "6.15.
|
|
29
|
-
"@phystack/phydevice-darwin-x64": "6.15.
|
|
30
|
-
"@phystack/phydevice-linux-arm64": "6.15.
|
|
31
|
-
"@phystack/phydevice-linux-x64": "6.15.
|
|
28
|
+
"@phystack/phydevice-darwin-arm64": "6.15.3",
|
|
29
|
+
"@phystack/phydevice-darwin-x64": "6.15.3",
|
|
30
|
+
"@phystack/phydevice-linux-arm64": "6.15.3",
|
|
31
|
+
"@phystack/phydevice-linux-x64": "6.15.3"
|
|
32
32
|
}
|
|
33
33
|
}
|