@fastybird/smart-panel-backend 1.1.0-alpha.10 → 1.1.0-alpha.12
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/plugins/devices-shelly-ng/delegates/delegates-manager.service.d.ts +3 -1
- package/dist/plugins/devices-shelly-ng/delegates/delegates-manager.service.js +25 -2
- package/dist/plugins/devices-shelly-ng/delegates/delegates-manager.service.js.map +1 -1
- package/dist/plugins/devices-shelly-ng/devices-shelly-ng.plugin.js +2 -0
- package/dist/plugins/devices-shelly-ng/devices-shelly-ng.plugin.js.map +1 -1
- package/dist/plugins/devices-shelly-ng/services/poll-placement-diagnostics.service.d.ts +48 -0
- package/dist/plugins/devices-shelly-ng/services/poll-placement-diagnostics.service.js +456 -0
- package/dist/plugins/devices-shelly-ng/services/poll-placement-diagnostics.service.js.map +1 -0
- package/dist/plugins/devices-shelly-ng/services/shelly-ng.service.d.ts +3 -1
- package/dist/plugins/devices-shelly-ng/services/shelly-ng.service.js +29 -6
- package/dist/plugins/devices-shelly-ng/services/shelly-ng.service.js.map +1 -1
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +2 -2
|
@@ -0,0 +1,456 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.PollPlacementDiagnosticsService = void 0;
|
|
13
|
+
const crypto_1 = require("crypto");
|
|
14
|
+
const fs_1 = require("fs");
|
|
15
|
+
const promises_1 = require("fs/promises");
|
|
16
|
+
const path_1 = require("path");
|
|
17
|
+
const perf_hooks_1 = require("perf_hooks");
|
|
18
|
+
const common_1 = require("@nestjs/common");
|
|
19
|
+
const UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
|
|
20
|
+
const MAX_DURATION_MS = 180_000;
|
|
21
|
+
const MAX_RECORDS = 64;
|
|
22
|
+
const MAX_BYTES = 256 * 1024;
|
|
23
|
+
const OWNER_SUFFIX = '.owner.json';
|
|
24
|
+
class ExportOwnershipError extends Error {
|
|
25
|
+
constructor(message) {
|
|
26
|
+
super(message);
|
|
27
|
+
this.name = 'ExportOwnershipError';
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
let PollPlacementDiagnosticsService = class PollPlacementDiagnosticsService {
|
|
31
|
+
constructor() {
|
|
32
|
+
this.processInstanceId = (0, crypto_1.randomUUID)();
|
|
33
|
+
this.observerRuntimeHash = this.computeRuntimeHash();
|
|
34
|
+
this.delegateObservations = new Map();
|
|
35
|
+
this.snapshot = null;
|
|
36
|
+
this.writePending = false;
|
|
37
|
+
this.publishRequested = false;
|
|
38
|
+
this.writePromise = null;
|
|
39
|
+
this.destroyed = false;
|
|
40
|
+
this.ownershipAcquired = false;
|
|
41
|
+
this.expiryTimer = null;
|
|
42
|
+
this.cycleSequence = 0;
|
|
43
|
+
this.config = this.parseConfig(process.env.FB_SHELLY_POLL_PLACEMENT);
|
|
44
|
+
this.ownerPath = this.config ? this.config.exportPath + OWNER_SUFFIX : null;
|
|
45
|
+
if (this.config) {
|
|
46
|
+
const now = this.now();
|
|
47
|
+
const nowUtc = this.utcNow();
|
|
48
|
+
this.snapshot = {
|
|
49
|
+
schemaVersion: 1,
|
|
50
|
+
runId: this.config.runId,
|
|
51
|
+
status: 'armed',
|
|
52
|
+
candidateStatus: 'invalidated',
|
|
53
|
+
candidateReason: 'awaiting-cycle',
|
|
54
|
+
configFingerprint: (0, crypto_1.createHash)('sha256').update(JSON.stringify(this.config)).digest('hex'),
|
|
55
|
+
processInstanceId: this.processInstanceId,
|
|
56
|
+
processId: process.pid,
|
|
57
|
+
sourceDeviceId: this.config.sourceDeviceId,
|
|
58
|
+
observerRuntimeHash: this.observerRuntimeHash,
|
|
59
|
+
backendClock: 'performance-now-v1',
|
|
60
|
+
armedAtMonotonicMs: now,
|
|
61
|
+
armedAtUtc: nowUtc,
|
|
62
|
+
expiresAtMonotonicMs: now + this.config.durationMs,
|
|
63
|
+
sequence: 0,
|
|
64
|
+
observations: [],
|
|
65
|
+
};
|
|
66
|
+
this.expiryTimer = setTimeout(() => this.expireIfNeeded(), this.config.durationMs);
|
|
67
|
+
this.expiryTimer.unref?.();
|
|
68
|
+
void this.publish();
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
async onModuleDestroy() {
|
|
72
|
+
if (this.expiryTimer) {
|
|
73
|
+
clearTimeout(this.expiryTimer);
|
|
74
|
+
this.expiryTimer = null;
|
|
75
|
+
}
|
|
76
|
+
if (this.snapshot && this.isActive()) {
|
|
77
|
+
this.snapshot.status = 'invalidated';
|
|
78
|
+
this.snapshot.reason = 'process-shutdown';
|
|
79
|
+
await this.publish();
|
|
80
|
+
}
|
|
81
|
+
else {
|
|
82
|
+
const pending = this.writePromise;
|
|
83
|
+
if (pending !== null)
|
|
84
|
+
await pending;
|
|
85
|
+
}
|
|
86
|
+
this.destroyed = true;
|
|
87
|
+
}
|
|
88
|
+
isEnabled() {
|
|
89
|
+
this.expireIfNeeded();
|
|
90
|
+
return this.snapshot !== null && !this.destroyed && this.isActive();
|
|
91
|
+
}
|
|
92
|
+
observeDelegate(observation) {
|
|
93
|
+
if (!this.snapshot || this.destroyed || !this.isActive())
|
|
94
|
+
return;
|
|
95
|
+
const previous = this.delegateObservations.get(observation.delegateId);
|
|
96
|
+
this.delegateObservations.set(observation.delegateId, observation);
|
|
97
|
+
if (previous &&
|
|
98
|
+
(previous.sourceDeviceId === this.snapshot.sourceDeviceId ||
|
|
99
|
+
observation.sourceDeviceId === this.snapshot.sourceDeviceId) &&
|
|
100
|
+
(previous.sourceDeviceId !== observation.sourceDeviceId ||
|
|
101
|
+
previous.generation !== observation.generation ||
|
|
102
|
+
observation.connected !== true)) {
|
|
103
|
+
this.invalidateCandidate('target-delegate-changed');
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
removeDelegate(delegateId) {
|
|
107
|
+
const previous = this.delegateObservations.get(delegateId);
|
|
108
|
+
this.delegateObservations.delete(delegateId);
|
|
109
|
+
if (previous?.sourceDeviceId === this.snapshot?.sourceDeviceId)
|
|
110
|
+
this.invalidateCandidate('target-delegate-removed');
|
|
111
|
+
}
|
|
112
|
+
invalidate(reason) {
|
|
113
|
+
if (!this.snapshot || this.destroyed || !this.isActive())
|
|
114
|
+
return;
|
|
115
|
+
this.snapshot.status = 'invalidated';
|
|
116
|
+
this.snapshot.reason = reason;
|
|
117
|
+
void this.publish();
|
|
118
|
+
}
|
|
119
|
+
invalidateCandidate(reason) {
|
|
120
|
+
if (!this.snapshot || this.destroyed || !this.isActive())
|
|
121
|
+
return;
|
|
122
|
+
this.snapshot.candidateStatus = 'invalidated';
|
|
123
|
+
this.snapshot.candidateReason = reason;
|
|
124
|
+
this.snapshot.sequence++;
|
|
125
|
+
void this.publish();
|
|
126
|
+
}
|
|
127
|
+
observeCycle(generation, intervalMs, delegates, activePollCount = 0, concurrencyCap = 10, inFlightDelegates = [], schedulerState = 'started') {
|
|
128
|
+
const snapshot = this.snapshot;
|
|
129
|
+
if (!snapshot || this.destroyed || !this.isActive())
|
|
130
|
+
return null;
|
|
131
|
+
if (!Number.isInteger(generation) || !Number.isInteger(intervalMs) || intervalMs < 1 || delegates.length === 0) {
|
|
132
|
+
return null;
|
|
133
|
+
}
|
|
134
|
+
const cycleEntryMonotonicMs = this.now();
|
|
135
|
+
const cycleEntryUtc = this.utcNow();
|
|
136
|
+
const registrationBeforeMs = this.now();
|
|
137
|
+
const registrationBeforeUtc = this.utcNow();
|
|
138
|
+
const ordered = delegates.slice();
|
|
139
|
+
const targetMatches = ordered.filter((id) => {
|
|
140
|
+
const delegate = this.delegateObservations.get(id);
|
|
141
|
+
return delegate?.sourceDeviceId === snapshot.sourceDeviceId && delegate.connected === true;
|
|
142
|
+
});
|
|
143
|
+
const targetIndex = targetMatches.length === 1 ? ordered.indexOf(targetMatches[0]) : -1;
|
|
144
|
+
const targetId = targetIndex >= 0 ? ordered[targetIndex] : null;
|
|
145
|
+
const target = targetId ? this.delegateObservations.get(targetId) : undefined;
|
|
146
|
+
const cycleSequence = ++this.cycleSequence;
|
|
147
|
+
snapshot.candidateStatus = targetId === null ? 'invalidated' : 'valid';
|
|
148
|
+
snapshot.candidateReason = targetId === null ? 'target-unresolved' : undefined;
|
|
149
|
+
snapshot.observations.push({
|
|
150
|
+
cycleSequence,
|
|
151
|
+
generation,
|
|
152
|
+
intervalMs,
|
|
153
|
+
anchorMonotonicMs: cycleEntryMonotonicMs,
|
|
154
|
+
anchorUtc: cycleEntryUtc,
|
|
155
|
+
connectedDelegateCount: ordered.length,
|
|
156
|
+
delegateOrderFingerprint: (0, crypto_1.createHash)('sha256').update(ordered.join('\n')).digest('hex'),
|
|
157
|
+
activePollCount,
|
|
158
|
+
concurrencyCap,
|
|
159
|
+
targetInFlight: targetId !== null && inFlightDelegates.includes(targetId),
|
|
160
|
+
schedulerState,
|
|
161
|
+
target: {
|
|
162
|
+
delegateId: targetId,
|
|
163
|
+
slotIndex: targetId ? targetIndex : null,
|
|
164
|
+
connected: target?.connected === true,
|
|
165
|
+
generation: target?.generation ?? null,
|
|
166
|
+
decision: 'unresolved',
|
|
167
|
+
skipReason: targetId ? 'slot-pending' : 'target-unresolved',
|
|
168
|
+
delayMs: targetId ? Math.floor((targetIndex * intervalMs) / ordered.length) : null,
|
|
169
|
+
registrationBeforeMs,
|
|
170
|
+
registrationBeforeUtc,
|
|
171
|
+
registrationAfterMs: null,
|
|
172
|
+
registrationAfterUtc: null,
|
|
173
|
+
},
|
|
174
|
+
});
|
|
175
|
+
snapshot.sequence++;
|
|
176
|
+
snapshot.status = 'ready';
|
|
177
|
+
this.enforceBounds();
|
|
178
|
+
void this.publish();
|
|
179
|
+
return cycleSequence;
|
|
180
|
+
}
|
|
181
|
+
completeCycleRegistration(cycleSequence) {
|
|
182
|
+
const snapshot = this.snapshot;
|
|
183
|
+
if (!snapshot || this.destroyed || !this.isActive())
|
|
184
|
+
return;
|
|
185
|
+
const observation = snapshot.observations.find((candidate) => candidate.cycleSequence === cycleSequence);
|
|
186
|
+
if (!observation)
|
|
187
|
+
return;
|
|
188
|
+
observation.target.registrationAfterMs = this.now();
|
|
189
|
+
observation.target.registrationAfterUtc = this.utcNow();
|
|
190
|
+
snapshot.sequence++;
|
|
191
|
+
void this.publish();
|
|
192
|
+
}
|
|
193
|
+
observeSlot(delegateId, generation, cycleSequence, decision, skipReason) {
|
|
194
|
+
const snapshot = this.snapshot;
|
|
195
|
+
if (!snapshot || this.destroyed || !this.isActive())
|
|
196
|
+
return;
|
|
197
|
+
const observation = snapshot.observations.find((candidate) => candidate.cycleSequence === cycleSequence);
|
|
198
|
+
if (!observation || observation.generation !== generation || observation.target.delegateId !== delegateId)
|
|
199
|
+
return;
|
|
200
|
+
observation.target.decision = decision;
|
|
201
|
+
observation.target.skipReason = skipReason;
|
|
202
|
+
snapshot.sequence++;
|
|
203
|
+
void this.publish();
|
|
204
|
+
}
|
|
205
|
+
isActive() {
|
|
206
|
+
return this.snapshot?.status === 'armed' || this.snapshot?.status === 'ready';
|
|
207
|
+
}
|
|
208
|
+
expireIfNeeded() {
|
|
209
|
+
if (!this.snapshot || this.destroyed || !this.isActive() || this.now() < this.snapshot.expiresAtMonotonicMs)
|
|
210
|
+
return;
|
|
211
|
+
this.snapshot.status = 'expired';
|
|
212
|
+
this.snapshot.reason = 'diagnostic-expired';
|
|
213
|
+
void this.publish();
|
|
214
|
+
}
|
|
215
|
+
enforceBounds() {
|
|
216
|
+
if (!this.snapshot)
|
|
217
|
+
return;
|
|
218
|
+
if (this.snapshot.observations.length <= MAX_RECORDS &&
|
|
219
|
+
Buffer.byteLength(JSON.stringify(this.snapshot)) <= MAX_BYTES)
|
|
220
|
+
return;
|
|
221
|
+
this.snapshot.status = 'overflow';
|
|
222
|
+
this.snapshot.reason = 'observation-bound-exceeded';
|
|
223
|
+
this.snapshot.observations = this.snapshot.observations.slice(0, MAX_RECORDS);
|
|
224
|
+
}
|
|
225
|
+
parseConfig(raw) {
|
|
226
|
+
if (!raw)
|
|
227
|
+
return null;
|
|
228
|
+
try {
|
|
229
|
+
if (Buffer.byteLength(raw, 'utf8') > 8192)
|
|
230
|
+
return null;
|
|
231
|
+
const value = JSON.parse(raw);
|
|
232
|
+
if (value.schemaVersion !== 1 || typeof value.runId !== 'string' || !UUID_RE.test(value.runId))
|
|
233
|
+
return null;
|
|
234
|
+
if (typeof value.sourceDeviceId !== 'string' || !UUID_RE.test(value.sourceDeviceId))
|
|
235
|
+
return null;
|
|
236
|
+
if (typeof value.exportPath !== 'string' || !value.exportPath.startsWith('/') || value.exportPath.includes('\0'))
|
|
237
|
+
return null;
|
|
238
|
+
const durationMs = value.durationMs === undefined ? MAX_DURATION_MS : value.durationMs;
|
|
239
|
+
if (typeof durationMs !== 'number' ||
|
|
240
|
+
!Number.isInteger(durationMs) ||
|
|
241
|
+
durationMs < 1000 ||
|
|
242
|
+
durationMs > MAX_DURATION_MS)
|
|
243
|
+
return null;
|
|
244
|
+
const allowed = new Set(['schemaVersion', 'runId', 'sourceDeviceId', 'exportPath', 'durationMs']);
|
|
245
|
+
if (Object.keys(value).some((key) => !allowed.has(key)))
|
|
246
|
+
return null;
|
|
247
|
+
return {
|
|
248
|
+
schemaVersion: 1,
|
|
249
|
+
runId: value.runId,
|
|
250
|
+
sourceDeviceId: value.sourceDeviceId,
|
|
251
|
+
exportPath: value.exportPath,
|
|
252
|
+
durationMs,
|
|
253
|
+
};
|
|
254
|
+
}
|
|
255
|
+
catch {
|
|
256
|
+
return null;
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
computeRuntimeHash() {
|
|
260
|
+
try {
|
|
261
|
+
return (0, crypto_1.createHash)('sha256').update((0, fs_1.readFileSync)(__filename)).digest('hex');
|
|
262
|
+
}
|
|
263
|
+
catch {
|
|
264
|
+
return (0, crypto_1.createHash)('sha256').update(__filename).digest('hex');
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
now() {
|
|
268
|
+
return perf_hooks_1.performance.now();
|
|
269
|
+
}
|
|
270
|
+
utcNow() {
|
|
271
|
+
return new Date().toISOString();
|
|
272
|
+
}
|
|
273
|
+
ownerRecord() {
|
|
274
|
+
return {
|
|
275
|
+
schemaVersion: 1,
|
|
276
|
+
runId: this.snapshot.runId,
|
|
277
|
+
processInstanceId: this.processInstanceId,
|
|
278
|
+
processId: process.pid,
|
|
279
|
+
configFingerprint: this.snapshot.configFingerprint,
|
|
280
|
+
};
|
|
281
|
+
}
|
|
282
|
+
async acquireOwnership() {
|
|
283
|
+
if (this.ownershipAcquired)
|
|
284
|
+
return;
|
|
285
|
+
if (!this.config || !this.ownerPath || !this.snapshot)
|
|
286
|
+
throw new ExportOwnershipError('diagnostic is disabled');
|
|
287
|
+
const directory = (0, path_1.dirname)(this.config.exportPath);
|
|
288
|
+
await (0, promises_1.mkdir)(directory, { recursive: true, mode: 0o700 });
|
|
289
|
+
const directoryStat = await (0, promises_1.lstat)(directory);
|
|
290
|
+
if (!directoryStat.isDirectory())
|
|
291
|
+
throw new ExportOwnershipError('export parent is not a directory');
|
|
292
|
+
if ((directoryStat.mode & 0o077) !== 0)
|
|
293
|
+
throw new ExportOwnershipError('export parent is not owner-only');
|
|
294
|
+
const existingOutput = await this.lstatIfExists(this.config.exportPath);
|
|
295
|
+
if (existingOutput?.isSymbolicLink())
|
|
296
|
+
throw new ExportOwnershipError('export output is a symlink');
|
|
297
|
+
if (existingOutput)
|
|
298
|
+
throw new ExportOwnershipError('export output already exists');
|
|
299
|
+
let ownerHandle;
|
|
300
|
+
try {
|
|
301
|
+
ownerHandle = await (0, promises_1.open)(this.ownerPath, 'wx', 0o600);
|
|
302
|
+
}
|
|
303
|
+
catch (error) {
|
|
304
|
+
if (error.code === 'EEXIST') {
|
|
305
|
+
throw new ExportOwnershipError('owner record already exists');
|
|
306
|
+
}
|
|
307
|
+
throw error;
|
|
308
|
+
}
|
|
309
|
+
try {
|
|
310
|
+
await ownerHandle.writeFile(`${JSON.stringify(this.ownerRecord())}\n`);
|
|
311
|
+
await ownerHandle.sync();
|
|
312
|
+
}
|
|
313
|
+
finally {
|
|
314
|
+
await ownerHandle.close();
|
|
315
|
+
}
|
|
316
|
+
await this.syncDirectory(directory);
|
|
317
|
+
this.ownershipAcquired = true;
|
|
318
|
+
}
|
|
319
|
+
async assertOwnership(requireOutput) {
|
|
320
|
+
if (!this.config || !this.ownerPath || !this.snapshot || !this.ownershipAcquired)
|
|
321
|
+
throw new ExportOwnershipError('export ownership is not acquired');
|
|
322
|
+
const directoryStat = await (0, promises_1.lstat)((0, path_1.dirname)(this.config.exportPath));
|
|
323
|
+
if (!directoryStat.isDirectory())
|
|
324
|
+
throw new ExportOwnershipError('export parent is not a directory');
|
|
325
|
+
if ((directoryStat.mode & 0o077) !== 0)
|
|
326
|
+
throw new ExportOwnershipError('export parent is not owner-only');
|
|
327
|
+
const ownerStat = await (0, promises_1.lstat)(this.ownerPath);
|
|
328
|
+
if (ownerStat.isSymbolicLink())
|
|
329
|
+
throw new ExportOwnershipError('owner record is a symlink');
|
|
330
|
+
if ((ownerStat.mode & 0o177) !== 0)
|
|
331
|
+
throw new ExportOwnershipError('owner record is not owner-only');
|
|
332
|
+
const ownerHandle = await (0, promises_1.open)(this.ownerPath, 'r');
|
|
333
|
+
let owner;
|
|
334
|
+
try {
|
|
335
|
+
owner = JSON.parse(await ownerHandle.readFile('utf8'));
|
|
336
|
+
}
|
|
337
|
+
finally {
|
|
338
|
+
await ownerHandle.close();
|
|
339
|
+
}
|
|
340
|
+
if (JSON.stringify(owner) !== JSON.stringify(this.ownerRecord()))
|
|
341
|
+
throw new ExportOwnershipError('export ownership changed');
|
|
342
|
+
const outputStat = await this.lstatIfExists(this.config.exportPath);
|
|
343
|
+
if (!outputStat) {
|
|
344
|
+
if (requireOutput)
|
|
345
|
+
throw new ExportOwnershipError('export output is missing');
|
|
346
|
+
return;
|
|
347
|
+
}
|
|
348
|
+
if (outputStat.isSymbolicLink())
|
|
349
|
+
throw new ExportOwnershipError('export output is a symlink');
|
|
350
|
+
if ((outputStat.mode & 0o177) !== 0)
|
|
351
|
+
throw new ExportOwnershipError('export output is not owner-only');
|
|
352
|
+
const outputHandle = await (0, promises_1.open)(this.config.exportPath, 'r');
|
|
353
|
+
let current;
|
|
354
|
+
try {
|
|
355
|
+
current = JSON.parse(await outputHandle.readFile('utf8'));
|
|
356
|
+
}
|
|
357
|
+
finally {
|
|
358
|
+
await outputHandle.close();
|
|
359
|
+
}
|
|
360
|
+
const expected = this.ownerRecord();
|
|
361
|
+
if (current.runId !== expected.runId ||
|
|
362
|
+
current.processInstanceId !== expected.processInstanceId ||
|
|
363
|
+
current.configFingerprint !== expected.configFingerprint) {
|
|
364
|
+
throw new ExportOwnershipError('export output belongs to another session');
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
async syncDirectory(directory) {
|
|
368
|
+
const handle = await (0, promises_1.open)(directory, 'r');
|
|
369
|
+
try {
|
|
370
|
+
await handle.sync();
|
|
371
|
+
}
|
|
372
|
+
finally {
|
|
373
|
+
await handle.close();
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
async lstatIfExists(path) {
|
|
377
|
+
try {
|
|
378
|
+
return await (0, promises_1.lstat)(path);
|
|
379
|
+
}
|
|
380
|
+
catch (error) {
|
|
381
|
+
if (error.code === 'ENOENT')
|
|
382
|
+
return null;
|
|
383
|
+
throw error;
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
publish() {
|
|
387
|
+
if (!this.snapshot || !this.config)
|
|
388
|
+
return Promise.resolve();
|
|
389
|
+
this.publishRequested = true;
|
|
390
|
+
if (this.writePending)
|
|
391
|
+
return this.writePromise ?? Promise.resolve();
|
|
392
|
+
this.writePending = true;
|
|
393
|
+
this.writePromise = this.flushPublish();
|
|
394
|
+
return this.writePromise;
|
|
395
|
+
}
|
|
396
|
+
async flushPublish() {
|
|
397
|
+
try {
|
|
398
|
+
do {
|
|
399
|
+
this.publishRequested = false;
|
|
400
|
+
await this.writeSnapshot();
|
|
401
|
+
} while (this.publishRequested && this.snapshot?.status !== 'writer-failure');
|
|
402
|
+
}
|
|
403
|
+
finally {
|
|
404
|
+
this.writePending = false;
|
|
405
|
+
this.writePromise = null;
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
async writeSnapshot() {
|
|
409
|
+
if (!this.snapshot || !this.config)
|
|
410
|
+
return;
|
|
411
|
+
let temporary = null;
|
|
412
|
+
let temporaryCreated = false;
|
|
413
|
+
try {
|
|
414
|
+
await this.acquireOwnership();
|
|
415
|
+
await this.assertOwnership(false);
|
|
416
|
+
temporary = this.config.exportPath + '.tmp-' + process.pid + '-' + this.snapshot.sequence;
|
|
417
|
+
await (0, promises_1.writeFile)(temporary, JSON.stringify(this.snapshot) + '\n', { mode: 0o600, flag: 'wx' });
|
|
418
|
+
temporaryCreated = true;
|
|
419
|
+
const handle = await (0, promises_1.open)(temporary, 'r');
|
|
420
|
+
try {
|
|
421
|
+
await handle.sync();
|
|
422
|
+
}
|
|
423
|
+
finally {
|
|
424
|
+
await handle.close();
|
|
425
|
+
}
|
|
426
|
+
const outputExists = (await this.lstatIfExists(this.config.exportPath)) !== null;
|
|
427
|
+
if (outputExists) {
|
|
428
|
+
await this.assertOwnership(true);
|
|
429
|
+
await (0, promises_1.rename)(temporary, this.config.exportPath);
|
|
430
|
+
temporaryCreated = false;
|
|
431
|
+
}
|
|
432
|
+
else {
|
|
433
|
+
await (0, promises_1.link)(temporary, this.config.exportPath);
|
|
434
|
+
await (0, promises_1.unlink)(temporary);
|
|
435
|
+
temporaryCreated = false;
|
|
436
|
+
}
|
|
437
|
+
await this.syncDirectory((0, path_1.dirname)(this.config.exportPath));
|
|
438
|
+
await this.assertOwnership(true);
|
|
439
|
+
}
|
|
440
|
+
catch (error) {
|
|
441
|
+
if (temporaryCreated && temporary !== null)
|
|
442
|
+
await (0, promises_1.unlink)(temporary).catch(() => undefined);
|
|
443
|
+
if (this.snapshot) {
|
|
444
|
+
this.snapshot.status = 'writer-failure';
|
|
445
|
+
this.snapshot.reason =
|
|
446
|
+
error instanceof ExportOwnershipError ? 'export-ownership-failed' : 'export-write-failed';
|
|
447
|
+
}
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
};
|
|
451
|
+
exports.PollPlacementDiagnosticsService = PollPlacementDiagnosticsService;
|
|
452
|
+
exports.PollPlacementDiagnosticsService = PollPlacementDiagnosticsService = __decorate([
|
|
453
|
+
(0, common_1.Injectable)(),
|
|
454
|
+
__metadata("design:paramtypes", [])
|
|
455
|
+
], PollPlacementDiagnosticsService);
|
|
456
|
+
//# sourceMappingURL=poll-placement-diagnostics.service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"poll-placement-diagnostics.service.js","sourceRoot":"","sources":["../../../../src/plugins/devices-shelly-ng/services/poll-placement-diagnostics.service.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,mCAAgD;AAChD,2BAAkC;AAElC,0CAA8F;AAC9F,+BAA+B;AAC/B,2CAAyC;AAEzC,2CAA6D;AAwE7D,MAAM,OAAO,GAAG,4EAA4E,CAAC;AAC7F,MAAM,eAAe,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eAAe,CAAC,IAAI,CAAC,CAAC;gBACjC,MAAM,IAAA,iBAAM,EAAC,SAAS,EAAE,IAAI,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;gBAChD,gBAAgB,GAAG,KAAK,CAAC;YAC1B,CAAC;iBAAM,CAAC;gBACP,MAAM,IAAA,eAAI,EAAC,SAAS,EAAE,IAAI,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;gBAC9C,MAAM,IAAA,iBAAM,EAAC,SAAS,CAAC,CAAC;gBACxB,gBAAgB,GAAG,KAAK,CAAC;YAC1B,CAAC;YACD,MAAM,IAAI,CAAC,aAAa,CAAC,IAAA,cAAO,EAAC,IAAI,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC,CAAC;YAC1D,MAAM,IAAI,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC;QAClC,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YAChB,IAAI,gBAAgB,IAAI,SAAS,KAAK,IAAI;gBAAE,MAAM,IAAA,iBAAM,EAAC,SAAS,CAAC,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,CAAC;YAC3F,IAAI,IAAI,CAAC,QAAQ,EAAE,CAAC;gBACnB,IAAI,CAAC,QAAQ,CAAC,MAAM,GAAG,gBAAgB,CAAC;gBACxC,IAAI,CAAC,QAAQ,CAAC,MAAM;oBACnB,KAAK,YAAY,oBAAoB,CAAC,CAAC,CAAC,yBAAyB,CAAC,CAAC,CAAC,qBAAqB,CAAC;YAC5F,CAAC;QACF,CAAC;IACF,CAAC;CACD,CAAA;AAraY,0EAA+B;0CAA/B,+BAA+B;IAD3C,IAAA,mBAAU,GAAE;;GACA,+BAA+B,CAqa3C"}
|
|
@@ -8,6 +8,7 @@ import { ManagedServiceManagerService } from '../../../modules/extensions/servic
|
|
|
8
8
|
import { DelegatesManagerService } from '../delegates/delegates-manager.service';
|
|
9
9
|
import { DatabaseDiscovererService } from './database-discoverer.service';
|
|
10
10
|
import { DeviceManagerService } from './device-manager.service';
|
|
11
|
+
import { PollPlacementDiagnosticsService } from './poll-placement-diagnostics.service';
|
|
11
12
|
import { ShellyWsServerService } from './shelly-ws-server.service';
|
|
12
13
|
export declare class ShellyNgService extends BaseManagedExtensionService {
|
|
13
14
|
private readonly configService;
|
|
@@ -18,6 +19,7 @@ export declare class ShellyNgService extends BaseManagedExtensionService {
|
|
|
18
19
|
private readonly deviceConnectivityService;
|
|
19
20
|
private readonly managedServiceManager;
|
|
20
21
|
private readonly wsServer;
|
|
22
|
+
private readonly pollPlacementDiagnostics;
|
|
21
23
|
private readonly logger;
|
|
22
24
|
readonly owner: {
|
|
23
25
|
readonly kind: "plugin";
|
|
@@ -40,7 +42,7 @@ export declare class ShellyNgService extends BaseManagedExtensionService {
|
|
|
40
42
|
private readonly discoveryQueue;
|
|
41
43
|
private processingDiscovery;
|
|
42
44
|
private discoveryGeneration;
|
|
43
|
-
constructor(configService: ConfigService, databaseDiscovererService: DatabaseDiscovererService, delegatesRegistryService: DelegatesManagerService, deviceManagerService: DeviceManagerService, devicesService: DevicesService, deviceConnectivityService: DeviceConnectivityService, managedServiceManager: ManagedServiceManagerService, wsServer: ShellyWsServerService);
|
|
45
|
+
constructor(configService: ConfigService, databaseDiscovererService: DatabaseDiscovererService, delegatesRegistryService: DelegatesManagerService, deviceManagerService: DeviceManagerService, devicesService: DevicesService, deviceConnectivityService: DeviceConnectivityService, managedServiceManager: ManagedServiceManagerService, wsServer: ShellyWsServerService, pollPlacementDiagnostics?: PollPlacementDiagnosticsService);
|
|
44
46
|
start(): Promise<void>;
|
|
45
47
|
stop(): Promise<void>;
|
|
46
48
|
isHealthy(): Promise<boolean>;
|
|
@@ -8,6 +8,9 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
8
8
|
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
9
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
10
|
};
|
|
11
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
12
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
13
|
+
};
|
|
11
14
|
var ShellyNgService_1;
|
|
12
15
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
16
|
exports.ShellyNgService = void 0;
|
|
@@ -25,9 +28,10 @@ const delegates_manager_service_1 = require("../delegates/delegates-manager.serv
|
|
|
25
28
|
const devices_shelly_ng_constants_1 = require("../devices-shelly-ng.constants");
|
|
26
29
|
const database_discoverer_service_1 = require("./database-discoverer.service");
|
|
27
30
|
const device_manager_service_1 = require("./device-manager.service");
|
|
31
|
+
const poll_placement_diagnostics_service_1 = require("./poll-placement-diagnostics.service");
|
|
28
32
|
const shelly_ws_server_service_1 = require("./shelly-ws-server.service");
|
|
29
33
|
let ShellyNgService = ShellyNgService_1 = class ShellyNgService extends base_managed_extension_service_1.BaseManagedExtensionService {
|
|
30
|
-
constructor(configService, databaseDiscovererService, delegatesRegistryService, deviceManagerService, devicesService, deviceConnectivityService, managedServiceManager, wsServer) {
|
|
34
|
+
constructor(configService, databaseDiscovererService, delegatesRegistryService, deviceManagerService, devicesService, deviceConnectivityService, managedServiceManager, wsServer, pollPlacementDiagnostics = new poll_placement_diagnostics_service_1.PollPlacementDiagnosticsService()) {
|
|
31
35
|
super();
|
|
32
36
|
this.configService = configService;
|
|
33
37
|
this.databaseDiscovererService = databaseDiscovererService;
|
|
@@ -37,6 +41,7 @@ let ShellyNgService = ShellyNgService_1 = class ShellyNgService extends base_man
|
|
|
37
41
|
this.deviceConnectivityService = deviceConnectivityService;
|
|
38
42
|
this.managedServiceManager = managedServiceManager;
|
|
39
43
|
this.wsServer = wsServer;
|
|
44
|
+
this.pollPlacementDiagnostics = pollPlacementDiagnostics;
|
|
40
45
|
this.logger = (0, logger_1.createExtensionLogger)(devices_shelly_ng_constants_1.DEVICES_SHELLY_NG_PLUGIN_NAME, 'ShellyService');
|
|
41
46
|
this.owner = { kind: 'plugin', type: devices_shelly_ng_constants_1.DEVICES_SHELLY_NG_PLUGIN_NAME };
|
|
42
47
|
this.serviceId = 'connector';
|
|
@@ -419,7 +424,7 @@ let ShellyNgService = ShellyNgService_1 = class ShellyNgService extends base_man
|
|
|
419
424
|
}
|
|
420
425
|
}
|
|
421
426
|
startStatusPoll() {
|
|
422
|
-
this.stopStatusPoll();
|
|
427
|
+
this.stopStatusPoll(this.state === 'started');
|
|
423
428
|
const intervalSec = this.config.statusPollInterval;
|
|
424
429
|
if (intervalSec <= 0) {
|
|
425
430
|
this.logger.log('Status polling disabled (interval = 0)');
|
|
@@ -427,8 +432,11 @@ let ShellyNgService = ShellyNgService_1 = class ShellyNgService extends base_man
|
|
|
427
432
|
}
|
|
428
433
|
this.scheduleStatusPollCycle(intervalSec * 1000, this.statusPollGeneration);
|
|
429
434
|
}
|
|
430
|
-
stopStatusPoll() {
|
|
435
|
+
stopStatusPoll(invalidateDiagnostics = true) {
|
|
431
436
|
this.statusPollGeneration++;
|
|
437
|
+
if (invalidateDiagnostics) {
|
|
438
|
+
this.pollPlacementDiagnostics.invalidate('poll-scheduler-stopped');
|
|
439
|
+
}
|
|
432
440
|
this.delegatesRegistryService.invalidateStatusPolls();
|
|
433
441
|
for (const timer of this.statusPollTimers) {
|
|
434
442
|
clearTimeout(timer);
|
|
@@ -441,10 +449,13 @@ let ShellyNgService = ShellyNgService_1 = class ShellyNgService extends base_man
|
|
|
441
449
|
return;
|
|
442
450
|
}
|
|
443
451
|
const delegates = this.delegatesRegistryService.getConnectedDelegateIds().slice().sort();
|
|
452
|
+
const cycleSequence = this.pollPlacementDiagnostics.observeCycle(generation, intervalMs, delegates, this.statusPollActive, ShellyNgService_1.STATUS_POLL_CONCURRENCY, Array.from(this.statusPollInFlight), this.state === 'starting' ? 'starting' : 'started');
|
|
444
453
|
for (const [index, delegateId] of delegates.entries()) {
|
|
445
454
|
const delay = Math.floor((index * intervalMs) / delegates.length);
|
|
446
|
-
this.scheduleStatusPollTimeout(() => this.runStatusPollSlot(delegateId, generation), delay);
|
|
455
|
+
this.scheduleStatusPollTimeout(() => this.runStatusPollSlot(delegateId, generation, cycleSequence), delay);
|
|
447
456
|
}
|
|
457
|
+
if (cycleSequence !== null)
|
|
458
|
+
this.pollPlacementDiagnostics.completeCycleRegistration(cycleSequence);
|
|
448
459
|
this.statusPollTimer = this.scheduleStatusPollTimeout(() => this.scheduleStatusPollCycle(intervalMs, generation), intervalMs);
|
|
449
460
|
}
|
|
450
461
|
scheduleStatusPollTimeout(callback, delayMs) {
|
|
@@ -455,13 +466,23 @@ let ShellyNgService = ShellyNgService_1 = class ShellyNgService extends base_man
|
|
|
455
466
|
this.statusPollTimers.add(timer);
|
|
456
467
|
return timer;
|
|
457
468
|
}
|
|
458
|
-
runStatusPollSlot(delegateId, generation) {
|
|
469
|
+
runStatusPollSlot(delegateId, generation, cycleSequence) {
|
|
459
470
|
if (this.state !== 'started' ||
|
|
460
471
|
generation !== this.statusPollGeneration ||
|
|
461
472
|
this.statusPollActive >= ShellyNgService_1.STATUS_POLL_CONCURRENCY ||
|
|
462
473
|
this.statusPollInFlight.has(delegateId)) {
|
|
474
|
+
this.pollPlacementDiagnostics.observeSlot(delegateId, generation, cycleSequence ?? -1, 'skipped', this.state !== 'started'
|
|
475
|
+
? 'lifecycle-inactive'
|
|
476
|
+
: generation !== this.statusPollGeneration
|
|
477
|
+
? 'generation-changed'
|
|
478
|
+
: this.statusPollActive >= ShellyNgService_1.STATUS_POLL_CONCURRENCY
|
|
479
|
+
? 'global-cap'
|
|
480
|
+
: 'delegate-in-flight');
|
|
463
481
|
return;
|
|
464
482
|
}
|
|
483
|
+
if (cycleSequence !== null) {
|
|
484
|
+
this.pollPlacementDiagnostics.observeSlot(delegateId, generation, cycleSequence, 'dispatch-attempt');
|
|
485
|
+
}
|
|
465
486
|
this.statusPollActive++;
|
|
466
487
|
this.statusPollInFlight.add(delegateId);
|
|
467
488
|
void this.delegatesRegistryService
|
|
@@ -497,6 +518,7 @@ ShellyNgService.STATUS_POLL_CONCURRENCY = 10;
|
|
|
497
518
|
ShellyNgService.STATUS_POLL_TIMEOUT_MS = 10_000;
|
|
498
519
|
exports.ShellyNgService = ShellyNgService = ShellyNgService_1 = __decorate([
|
|
499
520
|
(0, common_1.Injectable)(),
|
|
521
|
+
__param(8, (0, common_1.Optional)()),
|
|
500
522
|
__metadata("design:paramtypes", [config_service_1.ConfigService,
|
|
501
523
|
database_discoverer_service_1.DatabaseDiscovererService,
|
|
502
524
|
delegates_manager_service_1.DelegatesManagerService,
|
|
@@ -504,6 +526,7 @@ exports.ShellyNgService = ShellyNgService = ShellyNgService_1 = __decorate([
|
|
|
504
526
|
devices_service_1.DevicesService,
|
|
505
527
|
device_connectivity_service_1.DeviceConnectivityService,
|
|
506
528
|
managed_service_manager_service_1.ManagedServiceManagerService,
|
|
507
|
-
shelly_ws_server_service_1.ShellyWsServerService
|
|
529
|
+
shelly_ws_server_service_1.ShellyWsServerService,
|
|
530
|
+
poll_placement_diagnostics_service_1.PollPlacementDiagnosticsService])
|
|
508
531
|
], ShellyNgService);
|
|
509
532
|
//# sourceMappingURL=shelly-ng.service.js.map
|