@alwaysai/device-agent 1.2.0 → 1.3.0
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/application-control/environment-variables.d.ts +1 -1
- package/lib/application-control/environment-variables.d.ts.map +1 -1
- package/lib/cloud-connection/device-agent-cloud-connection.d.ts +3 -2
- package/lib/cloud-connection/device-agent-cloud-connection.d.ts.map +1 -1
- package/lib/cloud-connection/device-agent-cloud-connection.js +80 -59
- package/lib/cloud-connection/device-agent-cloud-connection.js.map +1 -1
- package/lib/cloud-connection/live-updates-handler.d.ts.map +1 -1
- package/lib/cloud-connection/live-updates-handler.js +2 -4
- package/lib/cloud-connection/live-updates-handler.js.map +1 -1
- package/lib/cloud-connection/live-updates-handler.test.js +1 -1
- package/lib/cloud-connection/live-updates-handler.test.js.map +1 -1
- package/lib/cloud-connection/passthrough-handler.d.ts.map +1 -1
- package/lib/cloud-connection/passthrough-handler.js +3 -6
- package/lib/cloud-connection/passthrough-handler.js.map +1 -1
- package/lib/cloud-connection/publisher.d.ts +5 -4
- package/lib/cloud-connection/publisher.d.ts.map +1 -1
- package/lib/cloud-connection/publisher.js +9 -8
- package/lib/cloud-connection/publisher.js.map +1 -1
- package/lib/cloud-connection/shadow-handler.d.ts +1 -0
- package/lib/cloud-connection/shadow-handler.d.ts.map +1 -1
- package/lib/cloud-connection/shadow-handler.js +5 -6
- package/lib/cloud-connection/shadow-handler.js.map +1 -1
- package/lib/cloud-connection/shadow-handler.test.js +9 -0
- package/lib/cloud-connection/shadow-handler.test.js.map +1 -1
- package/lib/cloud-connection/transaction-manager.d.ts +10 -0
- package/lib/cloud-connection/transaction-manager.d.ts.map +1 -0
- package/lib/cloud-connection/transaction-manager.js +41 -0
- package/lib/cloud-connection/transaction-manager.js.map +1 -0
- package/lib/cloud-connection/transaction-manager.test.d.ts +2 -0
- package/lib/cloud-connection/transaction-manager.test.d.ts.map +1 -0
- package/lib/cloud-connection/transaction-manager.test.js +63 -0
- package/lib/cloud-connection/transaction-manager.test.js.map +1 -0
- package/lib/device-control/device-control.d.ts +35 -24
- package/lib/device-control/device-control.d.ts.map +1 -1
- package/lib/device-control/device-control.js +46 -11
- package/lib/device-control/device-control.js.map +1 -1
- package/lib/subcommands/app/env-vars.d.ts.map +1 -1
- package/lib/subcommands/app/env-vars.js +15 -9
- package/lib/subcommands/app/env-vars.js.map +1 -1
- package/lib/subcommands/device/clean.d.ts.map +1 -1
- package/lib/subcommands/device/clean.js +14 -12
- package/lib/subcommands/device/clean.js.map +1 -1
- package/lib/subcommands/device/device.d.ts +1 -0
- package/lib/subcommands/device/device.d.ts.map +1 -1
- package/lib/subcommands/device/device.js +23 -16
- package/lib/subcommands/device/device.js.map +1 -1
- package/lib/subcommands/device/index.js +1 -1
- package/lib/subcommands/device/index.js.map +1 -1
- package/lib/util/logger.d.ts.map +1 -1
- package/lib/util/logger.js +1 -1
- package/lib/util/logger.js.map +1 -1
- package/lib/util/safe-rimraf.d.ts +2 -0
- package/lib/util/safe-rimraf.d.ts.map +1 -0
- package/lib/util/safe-rimraf.js +16 -0
- package/lib/util/safe-rimraf.js.map +1 -0
- package/package.json +3 -2
- package/readme.md +1 -0
- package/src/application-control/environment-variables.ts +1 -1
- package/src/cloud-connection/device-agent-cloud-connection.ts +124 -80
- package/src/cloud-connection/live-updates-handler.test.ts +2 -2
- package/src/cloud-connection/live-updates-handler.ts +2 -8
- package/src/cloud-connection/passthrough-handler.ts +8 -7
- package/src/cloud-connection/publisher.ts +27 -10
- package/src/cloud-connection/shadow-handler.test.ts +9 -0
- package/src/cloud-connection/shadow-handler.ts +6 -14
- package/src/cloud-connection/transaction-manager.test.ts +73 -0
- package/src/cloud-connection/transaction-manager.ts +43 -0
- package/src/device-control/device-control.ts +50 -12
- package/src/subcommands/app/env-vars.ts +17 -10
- package/src/subcommands/device/clean.ts +22 -13
- package/src/subcommands/device/device.ts +31 -20
- package/src/subcommands/device/index.ts +2 -2
- package/src/util/logger.ts +15 -10
- package/src/util/safe-rimraf.ts +14 -0
- package/lib/cloud-connection/transaction-queue.d.ts +0 -12
- package/lib/cloud-connection/transaction-queue.d.ts.map +0 -1
- package/lib/cloud-connection/transaction-queue.js +0 -38
- package/lib/cloud-connection/transaction-queue.js.map +0 -1
- package/lib/cloud-connection/transaction-queue.test.d.ts +0 -2
- package/lib/cloud-connection/transaction-queue.test.d.ts.map +0 -1
- package/lib/cloud-connection/transaction-queue.test.js +0 -46
- package/lib/cloud-connection/transaction-queue.test.js.map +0 -1
- package/src/cloud-connection/transaction-queue.test.ts +0 -55
- package/src/cloud-connection/transaction-queue.ts +0 -40
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"env-vars.js","sourceRoot":"","sources":["../../../src/subcommands/app/env-vars.ts"],"names":[],"mappings":";;;AAAA,mDAK6B;AAC7B,mEAAgE;AAChE,wGAAkG;AAClG,4CAAqC;
|
|
1
|
+
{"version":3,"file":"env-vars.js","sourceRoot":"","sources":["../../../src/subcommands/app/env-vars.ts"],"names":[],"mappings":";;;AAAA,mDAK6B;AAC7B,mEAAgE;AAChE,wGAAkG;AAClG,4CAAqC;AACrC,8CAA2C;AAE9B,QAAA,iBAAiB,GAAG,IAAA,mBAAO,EAAC;IACvC,IAAI,EAAE,cAAc;IACpB,WAAW,EAAE,8CAA8C;IAC3D,WAAW,EAAE;QACX,OAAO,EAAE,IAAA,0BAAc,EAAC;YACtB,WAAW,EAAE,YAAY;YACzB,QAAQ,EAAE,IAAI;SACf,CAAC;KACH;IACD,KAAK,CAAC,MAAM,CAAC,CAAC,EAAE,IAAI;QAClB,MAAM,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC;QACzB,MAAM,OAAO,GAAG,MAAM,IAAA,gCAAU,EAAC,EAAE,SAAS,EAAE,OAAO,EAAE,CAAC,CAAC;QACzD,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,SAAS,CAAC,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC;IA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AW,CAAC,eAAe,EAAE,CAAC,QAAQ,CAAC,MAAM,CAAC;QAC5D,MAAM,MAAM,GAAG;YACb,KAAK,EAAE;gBACL,OAAO,EAAE;oBACP,CAAC,OAAO,CAAC,EAAE;wBACT,OAAO;qBACR;iBACF;aACF;YACD,WAAW,EAAE,QAAQ;SACtB,CAAC;QACF,eAAM,CAAC,KAAK,CACV,wBAAwB,IAAI,CAAC,SAAS,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,EAAE,IAAI,EAAE,CAAC,CAAC,EAAE,CACrE,CAAC;QACF,WAAW,CAAC,SAAS,CAAC,OAAO,CAAC,KAAK,EAAE,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,CAAC;QAC7D,0DAA0D;QAC1D,MAAM,IAAA,eAAK,EAAC,KAAK,CAAC,CAAC;QAEnB,OAAO,WAAW,CAAC,eAAe,CAAC,OAAO,CAAC,EAAE;YAC3C,MAAM,IAAA,eAAK,EAAC,IAAI,CAAC,CAAC;SACnB;QACD,MAAM,WAAW,CAAC,IAAI,EAAE,CAAC;IAC3B,CAAC;CACF,CAAC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"clean.d.ts","sourceRoot":"","sources":["../../../src/subcommands/device/clean.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"clean.d.ts","sourceRoot":"","sources":["../../../src/subcommands/device/clean.ts"],"names":[],"mappings":"AAkBA,eAAO,MAAM,YAAY,yKAoCvB,CAAC"}
|
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.cleanCliLeaf = void 0;
|
|
4
4
|
const alwayscli_1 = require("@alwaysai/alwayscli");
|
|
5
|
-
const rimraf_1 = require("rimraf");
|
|
6
5
|
const logger_1 = require("../../util/logger");
|
|
7
6
|
const agent_config_1 = require("../../infrastructure/agent-config");
|
|
8
7
|
const device_1 = require("alwaysai/lib/core/device");
|
|
@@ -10,32 +9,35 @@ const directories_1 = require("../../util/directories");
|
|
|
10
9
|
const rabbitmq_connection_1 = require("../../local-connection/rabbitmq-connection");
|
|
11
10
|
const application_control_1 = require("../../application-control");
|
|
12
11
|
const paths_1 = require("alwaysai/lib/paths");
|
|
12
|
+
const safe_rimraf_1 = require("../../util/safe-rimraf");
|
|
13
13
|
exports.cleanCliLeaf = (0, alwayscli_1.CliLeaf)({
|
|
14
14
|
name: 'clean',
|
|
15
15
|
description: 'Remove all provisioning files',
|
|
16
16
|
async action(_, opts) {
|
|
17
|
-
|
|
18
|
-
|
|
17
|
+
logger_1.logger.info('Removing provisioning files.');
|
|
18
|
+
try {
|
|
19
|
+
if (await (0, rabbitmq_connection_1.checkRabbitMQContainerRunning)()) {
|
|
20
|
+
await (0, rabbitmq_connection_1.stopRabbitMQContainer)();
|
|
21
|
+
}
|
|
19
22
|
}
|
|
20
|
-
|
|
21
|
-
|
|
23
|
+
catch (e) {
|
|
24
|
+
logger_1.logger.error(`You may need to manually stop the container by running docker-compose down in the following directory: ${directories_1.DEVICE_AGENT_DOCKER_COMPOSE_PATH}`);
|
|
25
|
+
logger_1.logger.debug(`Error in checking / stopping RabbitMQ container: ${e}`);
|
|
26
|
+
}
|
|
27
|
+
await (0, safe_rimraf_1.default)(directories_1.DEVICE_AGENT_CFG_PATH);
|
|
22
28
|
logger_1.logger.debug('Checking for alwaysAI applications still running');
|
|
23
29
|
const apps = await (0, agent_config_1.AgentConfigFile)().getApps();
|
|
24
30
|
for (const app of apps) {
|
|
25
31
|
const { projectId } = app;
|
|
26
32
|
await (0, application_control_1.stopApp)({ projectId });
|
|
27
33
|
}
|
|
28
|
-
|
|
29
|
-
logger_1.logger.debug(`Removing ${paths_1.LOCAL_CERT_AND_KEY_DIR}`);
|
|
30
|
-
await (0, rimraf_1.rimraf)(paths_1.LOCAL_CERT_AND_KEY_DIR);
|
|
34
|
+
await (0, safe_rimraf_1.default)(paths_1.LOCAL_CERT_AND_KEY_DIR);
|
|
31
35
|
logger_1.logger.debug(`Removing ${(0, agent_config_1.AgentConfigFile)().path}`);
|
|
32
36
|
(0, agent_config_1.AgentConfigFile)().remove();
|
|
33
37
|
logger_1.logger.debug(`Removing ${(0, device_1.DeviceConfigFile)().path}`);
|
|
34
38
|
(0, device_1.DeviceConfigFile)().remove();
|
|
35
|
-
|
|
36
|
-
await (0,
|
|
37
|
-
logger_1.logger.debug(`Removing ${directories_1.APP_ROOT}`);
|
|
38
|
-
await (0, rimraf_1.rimraf)(directories_1.APP_ROOT);
|
|
39
|
+
await (0, safe_rimraf_1.default)(directories_1.CREDENTIALS_FILE_PATH);
|
|
40
|
+
await (0, safe_rimraf_1.default)(directories_1.APP_ROOT);
|
|
39
41
|
logger_1.logger.info('Device configuration cleaned');
|
|
40
42
|
}
|
|
41
43
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"clean.js","sourceRoot":"","sources":["../../../src/subcommands/device/clean.ts"],"names":[],"mappings":";;;AAAA,mDAA8C;AAC9C,
|
|
1
|
+
{"version":3,"file":"clean.js","sourceRoot":"","sources":["../../../src/subcommands/device/clean.ts"],"names":[],"mappings":";;;AAAA,mDAA8C;AAC9C,8CAA2C;AAC3C,oEAAoE;AACpE,qDAA4D;AAC5D,wDAKgC;AAChC,oFAGoD;AACpD,mEAAoD;AACpD,8CAA4D;AAC5D,wDAAgD;AAEnC,QAAA,YAAY,GAAG,IAAA,mBAAO,EAAC;IAClC,IAAI,EAAE,OAAO;IACb,WAAW,EAAE,+BAA+B;IAC5C,KAAK,CAAC,MAAM,CAAC,CAAC,EAAE,IAAI;QAClB,eAAM,CAAC,IAAI,CAAC,8BAA8B,CAAC,CAAC;QAC5C,IAAI;YACF,IAAI,MAAM,IAAA,mDAA6B,GAAE,EAAE;gBACzC,MAAM,IAAA,2CAAqB,GAAE,CAAC;aAC/B;SACF;QAAC,OAAO,CAAC,EAAE;YACV,eAAM,CAAC,KAAK,CACV,0GAA0G,8CAAgC,EAAE,CAC7I,CAAC;YACF,eAAM,CAAC,KAAK,CAAC,oDAAoD,CAAC,EAAE,CAAC,CAAC;SACvE;QAED,MAAM,IAAA,qBAAU,EAAC,mCAAqB,CAAC,CAAC;QAExC,eAAM,CAAC,KAAK,CAAC,kDAAkD,CAAC,CAAC;QACjE,MAAM,IAAI,GAAG,MAAM,IAAA,8BAAe,GAAE,CAAC,OAAO,EAAE,CAAC;QAC/C,KAAK,MAAM,GAAG,IAAI,IAAI,EAAE;YACtB,MAAM,EAAE,SAAS,EAAE,GAAG,GAAG,CAAC;YAC1B,MAAM,IAAA,6BAAO,EAAC,EAAE,SAAS,EAAE,CAAC,CAAC;SAC9B;QACD,MAAM,IAAA,qBAAU,EAAC,8BAAsB,CAAC,CAAC;QAEzC,eAAM,CAAC,KAAK,CAAC,YAAY,IAAA,8BAAe,GAAE,CAAC,IAAI,EAAE,CAAC,CAAC;QACnD,IAAA,8BAAe,GAAE,CAAC,MAAM,EAAE,CAAC;QAC3B,eAAM,CAAC,KAAK,CAAC,YAAY,IAAA,yBAAgB,GAAE,CAAC,IAAI,EAAE,CAAC,CAAC;QACpD,IAAA,yBAAgB,GAAE,CAAC,MAAM,EAAE,CAAC;QAE5B,MAAM,IAAA,qBAAU,EAAC,mCAAqB,CAAC,CAAC;QACxC,MAAM,IAAA,qBAAU,EAAC,sBAAQ,CAAC,CAAC;QAE3B,eAAM,CAAC,IAAI,CAAC,8BAA8B,CAAC,CAAC;IAC9C,CAAC;CACF,CAAC,CAAC"}
|
|
@@ -3,4 +3,5 @@ export declare const initCliLeaf: import("@alwaysai/alwayscli/lib/types").CliLea
|
|
|
3
3
|
description: import("@alwaysai/alwayscli").CliInput<string | undefined, false>;
|
|
4
4
|
}, import("@alwaysai/alwayscli").CliInput<undefined, false>>;
|
|
5
5
|
export declare const getInfoCliLeaf: import("@alwaysai/alwayscli/lib/types").CliLeaf<import("@alwaysai/alwayscli").CliInput<undefined, false>, {}, import("@alwaysai/alwayscli").CliInput<undefined, false>>;
|
|
6
|
+
export declare const restartCliLeaf: import("@alwaysai/alwayscli/lib/types").CliLeaf<import("@alwaysai/alwayscli").CliInput<undefined, false>, {}, import("@alwaysai/alwayscli").CliInput<undefined, false>>;
|
|
6
7
|
//# sourceMappingURL=device.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"device.d.ts","sourceRoot":"","sources":["../../../src/subcommands/device/device.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"device.d.ts","sourceRoot":"","sources":["../../../src/subcommands/device/device.ts"],"names":[],"mappings":"AA0BA,eAAO,MAAM,WAAW;;;4DA6EtB,CAAC;AAEH,eAAO,MAAM,cAAc,yKA4BzB,CAAC;AAEH,eAAO,MAAM,cAAc,yKAOzB,CAAC"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getInfoCliLeaf = exports.initCliLeaf = void 0;
|
|
3
|
+
exports.restartCliLeaf = exports.getInfoCliLeaf = exports.initCliLeaf = void 0;
|
|
4
4
|
const alwayscli_1 = require("@alwaysai/alwayscli");
|
|
5
5
|
const app_1 = require("alwaysai/lib/core/app");
|
|
6
6
|
const uuid_1 = require("uuid");
|
|
@@ -72,24 +72,31 @@ exports.getInfoCliLeaf = (0, alwayscli_1.CliLeaf)({
|
|
|
72
72
|
description: 'Get device info',
|
|
73
73
|
namedInputs: {},
|
|
74
74
|
async action(_, opts) {
|
|
75
|
+
var _a;
|
|
75
76
|
const cpuDetails = await (0, device_control_1.getCpuDetails)();
|
|
76
77
|
const diskDetails = await (0, device_control_1.getDiskDetails)();
|
|
77
78
|
const memDetails = await (0, device_control_1.getMemDetails)();
|
|
78
|
-
const
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
79
|
+
const out = {
|
|
80
|
+
'CPU Utilization': `Used ${cpuDetails.usedPerc.toFixed(2)}%, Temperature ${cpuDetails.temperature} °C`,
|
|
81
|
+
'Disk Utilization': `${diskDetails.usedGb} GB / ${diskDetails.usedGb + diskDetails.freeGb} GB`,
|
|
82
|
+
'Memory Utilization': `${memDetails.usedMb} MB / ${memDetails.usedMb + memDetails.freeMb} MB`
|
|
83
|
+
};
|
|
84
|
+
console.table(out);
|
|
85
|
+
const systemInfo = await (0, device_control_1.getSystemInformation)();
|
|
86
|
+
console.table(systemInfo.os);
|
|
87
|
+
console.table(systemInfo.cpu);
|
|
88
|
+
console.table((_a = systemInfo.disk) === null || _a === void 0 ? void 0 : _a.drives);
|
|
89
|
+
console.table(systemInfo.device);
|
|
90
|
+
console.table(systemInfo.network);
|
|
91
|
+
console.table(systemInfo.versions);
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
exports.restartCliLeaf = (0, alwayscli_1.CliLeaf)({
|
|
95
|
+
name: 'restart',
|
|
96
|
+
description: 'Restart the device',
|
|
97
|
+
namedInputs: {},
|
|
98
|
+
async action(_, opts) {
|
|
99
|
+
await (0, device_control_1.reboot)();
|
|
93
100
|
}
|
|
94
101
|
});
|
|
95
102
|
//# sourceMappingURL=device.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"device.js","sourceRoot":"","sources":["../../../src/subcommands/device/device.ts"],"names":[],"mappings":";;;AAAA,mDAA8D;AAC9D,+CAA8D;AAC9D,+BAAoC;AACpC,gEAAsE;AACtE,2BAAgC;AAChC,wDAA4E;AAC5E,wDAIgC;AAEhC,4CAA8C;AAC9C,
|
|
1
|
+
{"version":3,"file":"device.js","sourceRoot":"","sources":["../../../src/subcommands/device/device.ts"],"names":[],"mappings":";;;AAAA,mDAA8D;AAC9D,+CAA8D;AAC9D,+BAAoC;AACpC,gEAAsE;AACtE,2BAAgC;AAChC,wDAA4E;AAC5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C;IACjB,CAAC;CACF,CAAC,CAAC"}
|
|
@@ -7,6 +7,6 @@ const clean_1 = require("./clean");
|
|
|
7
7
|
exports.deviceCliBranch = (0, alwayscli_1.CliBranch)({
|
|
8
8
|
name: 'device',
|
|
9
9
|
description: 'Manage current device',
|
|
10
|
-
subcommands: [device_1.initCliLeaf, device_1.getInfoCliLeaf, clean_1.cleanCliLeaf]
|
|
10
|
+
subcommands: [device_1.initCliLeaf, device_1.getInfoCliLeaf, clean_1.cleanCliLeaf, device_1.restartCliLeaf]
|
|
11
11
|
});
|
|
12
12
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/subcommands/device/index.ts"],"names":[],"mappings":";;;AAAA,mDAAgD;AAChD,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/subcommands/device/index.ts"],"names":[],"mappings":";;;AAAA,mDAAgD;AAChD,qCAAuE;AACvE,mCAAuC;AAE1B,QAAA,eAAe,GAAG,IAAA,qBAAS,EAAC;IACvC,IAAI,EAAE,QAAQ;IACd,WAAW,EAAE,uBAAuB;IACpC,WAAW,EAAE,CAAC,oBAAW,EAAE,uBAAc,EAAE,oBAAY,EAAE,uBAAc,CAAC;CACzE,CAAC,CAAC"}
|
package/lib/util/logger.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../src/util/logger.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,OAAO,MAAM,SAAS,CAAC;AACnC,OAAO,2BAA2B,CAAC;
|
|
1
|
+
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../src/util/logger.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,OAAO,MAAM,SAAS,CAAC;AACnC,OAAO,2BAA2B,CAAC;AAsBnC,eAAO,MAAM,MAAM,gBAajB,CAAC"}
|
package/lib/util/logger.js
CHANGED
|
@@ -7,7 +7,7 @@ const path = require("path");
|
|
|
7
7
|
const paths_1 = require("alwaysai/lib/paths");
|
|
8
8
|
const environment_1 = require("../environment");
|
|
9
9
|
const LOG_LEVEL = environment_1.ALWAYSAI_LOG_LEVEL || 'info';
|
|
10
|
-
const transports = environment_1.ALWAYSAI_LOG_TO_CONSOLE
|
|
10
|
+
const transports = environment_1.ALWAYSAI_LOG_TO_CONSOLE || environment_1.ALWAYSAI_DEVICE_AGENT_MODE !== 'cloud'
|
|
11
11
|
? [new winston.transports.Console({ level: LOG_LEVEL })]
|
|
12
12
|
: [
|
|
13
13
|
new winston.transports.DailyRotateFile({
|
package/lib/util/logger.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"logger.js","sourceRoot":"","sources":["../../src/util/logger.ts"],"names":[],"mappings":";;;AAAA,mCAAmC;AACnC,qCAAmC;AACnC,6BAA6B;AAC7B,8CAA6C;AAC7C,
|
|
1
|
+
{"version":3,"file":"logger.js","sourceRoot":"","sources":["../../src/util/logger.ts"],"names":[],"mappings":";;;AAAA,mCAAmC;AACnC,qCAAmC;AACnC,6BAA6B;AAC7B,8CAA6C;AAC7C,gDAIwB;AAExB,MAAM,SAAS,GAAG,gCAAkB,IAAI,MAAM,CAAC;AAE/C,MAAM,UAAU,GACd,qCAAuB,IAAI,wCAA0B,KAAK,OAAO;IAC/D,CAAC,CAAC,CAAC,IAAI,OAAO,CAAC,UAAU,CAAC,OAAO,CAAC,EAAE,KAAK,EAAE,SAAS,EAAE,CAAC,CAAC;IACxD,CAAC,CAAC;QACE,IAAI,OAAO,CAAC,UAAU,CAAC,eAAe,CAAC;YACrC,QAAQ,EAAE,IAAI,CAAC,IAAI,CAAC,eAAO,EAAE,YAAY,EAAE,gBAAgB,CAAC;YAC5D,OAAO,EAAE,IAAI;YACb,QAAQ,EAAE,IAAI;SACf,CAAC;KACH,CAAC;AAEK,QAAA,MAAM,GAAG,OAAO,CAAC,YAAY,CAAC;IACzC,KAAK,EAAE,SAAS;IAChB,MAAM,EAAE,OAAO,CAAC,MAAM,CAAC,OAAO,CAC5B,OAAO,CAAC,MAAM,CAAC,SAAS,EAAE,EAC1B,OAAO,CAAC,MAAM,CAAC,QAAQ,EAAE,EACzB,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,EACtC,OAAO,CAAC,MAAM,CAAC,KAAK,EAAE,EACtB,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,EACvB,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,SAAS,GAAG,EAAE,EAAE,KAAK,GAAG,EAAE,EAAE,OAAO,GAAG,EAAE,EAAE,EAAE,EAAE;QACrE,OAAO,IAAI,SAAS,KAAK,KAAK,KAAK,OAAO,EAAE,CAAC;IAC/C,CAAC,CAAC,CACH;IACD,UAAU;CACX,CAAC,CAAC;AAEH,cAAM,CAAC,IAAI,CAAC,sCAAsC,SAAS,EAAE,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"safe-rimraf.d.ts","sourceRoot":"","sources":["../../src/util/safe-rimraf.ts"],"names":[],"mappings":"AAGA,wBAA8B,UAAU,CAAC,IAAI,EAAE,MAAM,iBAUpD"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const rimraf_1 = require("rimraf");
|
|
4
|
+
const logger_1 = require("../util/logger");
|
|
5
|
+
async function safeRimraf(path) {
|
|
6
|
+
logger_1.logger.debug(`Removing ${path}`);
|
|
7
|
+
try {
|
|
8
|
+
await (0, rimraf_1.rimraf)(path);
|
|
9
|
+
}
|
|
10
|
+
catch (e) {
|
|
11
|
+
logger_1.logger.error(`Failed to remove ${path}. Please manually delete the file or directory.`);
|
|
12
|
+
logger_1.logger.debug(`Error removing ${path}: ${e}`);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
exports.default = safeRimraf;
|
|
16
|
+
//# sourceMappingURL=safe-rimraf.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"safe-rimraf.js","sourceRoot":"","sources":["../../src/util/safe-rimraf.ts"],"names":[],"mappings":";;AAAA,mCAAgC;AAChC,2CAAwC;AAEzB,KAAK,UAAU,UAAU,CAAC,IAAY;IACnD,eAAM,CAAC,KAAK,CAAC,YAAY,IAAI,EAAE,CAAC,CAAC;IACjC,IAAI;QACF,MAAM,IAAA,eAAM,EAAC,IAAI,CAAC,CAAC;KACpB;IAAC,OAAO,CAAC,EAAE;QACV,eAAM,CAAC,KAAK,CACV,oBAAoB,IAAI,iDAAiD,CAC1E,CAAC;QACF,eAAM,CAAC,KAAK,CAAC,kBAAkB,IAAI,KAAK,CAAC,EAAE,CAAC,CAAC;KAC9C;AACH,CAAC;AAVD,6BAUC"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@alwaysai/device-agent",
|
|
3
3
|
"description": "The alwaysAI Device Agent",
|
|
4
|
-
"version": "1.
|
|
4
|
+
"version": "1.3.0",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "lib/index.d.ts",
|
|
7
7
|
"publishConfig": {
|
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
"@alwaysai/alwayscli": "0.3.2",
|
|
38
38
|
"@alwaysai/app-configuration-schemas": "0.1.0",
|
|
39
39
|
"@alwaysai/config-nodejs": "0.3.0",
|
|
40
|
-
"@alwaysai/device-agent-schemas": "2.1.
|
|
40
|
+
"@alwaysai/device-agent-schemas": "2.1.9",
|
|
41
41
|
"ajv": "8.11.0",
|
|
42
42
|
"alwaysai": "2.2.0",
|
|
43
43
|
"amqplib": "0.10.3",
|
|
@@ -59,6 +59,7 @@
|
|
|
59
59
|
"@types/destroy": "1.0.0",
|
|
60
60
|
"@types/jest": "28.1.2",
|
|
61
61
|
"@types/node": "16.11.12",
|
|
62
|
+
"@types/node-os-utils": "^1.3.4",
|
|
62
63
|
"@types/sinon": "10.0.6",
|
|
63
64
|
"@typescript-eslint/eslint-plugin": "^5.48.0",
|
|
64
65
|
"@typescript-eslint/parser": "^5.48.0",
|
package/readme.md
CHANGED
|
@@ -22,6 +22,7 @@ change.
|
|
|
22
22
|
* `docker` version >= 19.03
|
|
23
23
|
* `curl` installed (required to download provisioning scripts)
|
|
24
24
|
* Passwordless `sudo` for `npm` if using `pm2`
|
|
25
|
+
* Passwordless `sudo` for `/sbin/shutdown` for device restart functionality
|
|
25
26
|
|
|
26
27
|
To enable passwordless `sudo` for `npm` for the current user, run `sudo visudo`
|
|
27
28
|
and add the following line to the end of the file:
|
|
@@ -21,7 +21,8 @@ import {
|
|
|
21
21
|
AppStateControlPayload,
|
|
22
22
|
AppVersionControlInstallPayload,
|
|
23
23
|
AppVersionControlUninstallPayload,
|
|
24
|
-
ToClientMessage
|
|
24
|
+
ToClientMessage,
|
|
25
|
+
DeviceActionPayload
|
|
25
26
|
} from '@alwaysai/device-agent-schemas';
|
|
26
27
|
import { getDeviceUuid } from '../util/get-device-id';
|
|
27
28
|
import { logger } from '../util/logger';
|
|
@@ -49,19 +50,19 @@ import { getStatusResponsePayload } from './messages';
|
|
|
49
50
|
import { ModelsInstallResponsePayload } from '@alwaysai/device-agent-schemas';
|
|
50
51
|
import sleep from '../util/sleep';
|
|
51
52
|
import { createAppBackup, rollbackApp } from '../application-control/backup';
|
|
52
|
-
import {
|
|
53
|
+
import { TransactionManager } from './transaction-manager';
|
|
53
54
|
import {
|
|
54
55
|
buildSignedUrlsRequestMessage,
|
|
55
56
|
buildStatusResponseMessage
|
|
56
57
|
} from './message-builder';
|
|
57
|
-
import {
|
|
58
|
+
import { reboot } from '../device-control/device-control';
|
|
58
59
|
|
|
59
60
|
export class DeviceAgentCloudConnection {
|
|
60
61
|
private shadowHandler: ShadowHandler;
|
|
61
62
|
public publisher: Publisher;
|
|
62
63
|
private cmdStatusMgr: CmdStatusManager;
|
|
63
64
|
private liveUpdatesHandler: LiveUpdatesHandler;
|
|
64
|
-
private
|
|
65
|
+
private txnMgr: TransactionManager;
|
|
65
66
|
private device = awsIot.device;
|
|
66
67
|
|
|
67
68
|
private clientId = getDeviceUuid();
|
|
@@ -185,6 +186,21 @@ export class DeviceAgentCloudConnection {
|
|
|
185
186
|
return true;
|
|
186
187
|
};
|
|
187
188
|
|
|
189
|
+
private async handleDeviceAction(payload: DeviceActionPayload) {
|
|
190
|
+
const { system_restart } = keyMirrors.deviceAction;
|
|
191
|
+
switch (payload.action) {
|
|
192
|
+
case system_restart: {
|
|
193
|
+
await reboot();
|
|
194
|
+
break;
|
|
195
|
+
}
|
|
196
|
+
default: {
|
|
197
|
+
logger.info(
|
|
198
|
+
`Unrecognized device action requested: '${payload.action}'.`
|
|
199
|
+
);
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
|
|
188
204
|
private async publishCloudRequest(message: ToCloudMessage) {
|
|
189
205
|
this.publisher.publishToCloud(message);
|
|
190
206
|
}
|
|
@@ -223,6 +239,7 @@ export class DeviceAgentCloudConnection {
|
|
|
223
239
|
|
|
224
240
|
try {
|
|
225
241
|
const out: R = await func(...args);
|
|
242
|
+
this.shadowHandler.clearAppConfig(projectId);
|
|
226
243
|
await this.shadowHandler.updateProjectShadow(projectId);
|
|
227
244
|
return out;
|
|
228
245
|
} catch (errorAppUpdate) {
|
|
@@ -274,13 +291,13 @@ export class DeviceAgentCloudConnection {
|
|
|
274
291
|
await this.liveUpdatesHandler.disableTransactionStatus({
|
|
275
292
|
txId
|
|
276
293
|
});
|
|
277
|
-
const
|
|
294
|
+
const successStatusResponsePayload = await getStatusResponsePayload(
|
|
278
295
|
keyMirrors.statusResponse.success,
|
|
279
296
|
''
|
|
280
297
|
);
|
|
281
298
|
// Send final status message
|
|
282
299
|
const message = await buildStatusResponseMessage(
|
|
283
|
-
|
|
300
|
+
successStatusResponsePayload,
|
|
284
301
|
txId
|
|
285
302
|
);
|
|
286
303
|
this.publisher.publishToClient(message);
|
|
@@ -311,62 +328,60 @@ export class DeviceAgentCloudConnection {
|
|
|
311
328
|
}
|
|
312
329
|
}
|
|
313
330
|
|
|
314
|
-
private
|
|
315
|
-
|
|
331
|
+
private handleAppConfigUpdate = async (
|
|
332
|
+
update: ShadowUpdate,
|
|
316
333
|
txId: string
|
|
317
334
|
): Promise<boolean> => {
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
this.publisher.publishToCloud(message);
|
|
335
|
+
const { projectId, appCfgUpdate, envVarUpdate } = update;
|
|
336
|
+
|
|
337
|
+
if (
|
|
338
|
+
appCfgUpdate &&
|
|
339
|
+
appCfgUpdate.updatedModels &&
|
|
340
|
+
Object.keys(appCfgUpdate.updatedModels).length
|
|
341
|
+
) {
|
|
342
|
+
// When there are model updates request signed URLs and wait to apply config changes
|
|
343
|
+
const { updatedModels } = appCfgUpdate;
|
|
344
|
+
|
|
345
|
+
logger.debug(
|
|
346
|
+
`Requesting presigned urls from cloud for model versions: ${JSON.stringify(
|
|
347
|
+
updatedModels
|
|
348
|
+
)}`
|
|
349
|
+
);
|
|
350
|
+
const modelsOnlyUrlsRequestPayload: SignedUrlsRequestPayload = {
|
|
351
|
+
modelsOnlyUrlsRequest: {
|
|
352
|
+
projectId,
|
|
353
|
+
models: updatedModels
|
|
354
|
+
}
|
|
355
|
+
};
|
|
356
|
+
const message = await buildSignedUrlsRequestMessage(
|
|
357
|
+
modelsOnlyUrlsRequestPayload,
|
|
358
|
+
txId
|
|
359
|
+
);
|
|
360
|
+
this.publisher.publishToCloud(message);
|
|
345
361
|
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
362
|
+
this.appCfgUpdateQueue.push(update);
|
|
363
|
+
return false;
|
|
364
|
+
}
|
|
349
365
|
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
366
|
+
if (appCfgUpdate) {
|
|
367
|
+
await this.atomicApplicationUpdate(
|
|
368
|
+
updateAppCfg,
|
|
369
|
+
[
|
|
370
|
+
{
|
|
371
|
+
projectId,
|
|
372
|
+
newAppCfg: appCfgUpdate.newAppCfg
|
|
373
|
+
}
|
|
374
|
+
],
|
|
375
|
+
projectId
|
|
376
|
+
);
|
|
377
|
+
}
|
|
362
378
|
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
}
|
|
379
|
+
if (envVarUpdate) {
|
|
380
|
+
await this.atomicApplicationUpdate(
|
|
381
|
+
setEnv,
|
|
382
|
+
[{ projectId, envVars: envVarUpdate.envVars }],
|
|
383
|
+
projectId
|
|
384
|
+
);
|
|
370
385
|
}
|
|
371
386
|
return true;
|
|
372
387
|
};
|
|
@@ -392,7 +407,7 @@ export class DeviceAgentCloudConnection {
|
|
|
392
407
|
this.publisher,
|
|
393
408
|
this.clientId
|
|
394
409
|
);
|
|
395
|
-
this.
|
|
410
|
+
this.txnMgr = new TransactionManager();
|
|
396
411
|
|
|
397
412
|
this.subscribe(this.toDeviceTopic);
|
|
398
413
|
this.subscribe(this.secureTunnelNotifyTopic);
|
|
@@ -450,7 +465,7 @@ export class DeviceAgentCloudConnection {
|
|
|
450
465
|
const projectId = payload.projectId;
|
|
451
466
|
|
|
452
467
|
try {
|
|
453
|
-
this.
|
|
468
|
+
this.txnMgr.addTransaction(txId, projectId);
|
|
454
469
|
const completed = await this.atomicCmd({
|
|
455
470
|
func: this.handleAppStateControl,
|
|
456
471
|
args: [message.payload],
|
|
@@ -458,7 +473,7 @@ export class DeviceAgentCloudConnection {
|
|
|
458
473
|
txId
|
|
459
474
|
});
|
|
460
475
|
if (completed) {
|
|
461
|
-
this.
|
|
476
|
+
this.txnMgr.completeTransaction(txId);
|
|
462
477
|
}
|
|
463
478
|
} catch (e) {
|
|
464
479
|
logger.error(
|
|
@@ -477,7 +492,7 @@ export class DeviceAgentCloudConnection {
|
|
|
477
492
|
? payload.appReleaseHash
|
|
478
493
|
: undefined;
|
|
479
494
|
try {
|
|
480
|
-
this.
|
|
495
|
+
this.txnMgr.addTransaction(txId, projectId);
|
|
481
496
|
const completed = await this.atomicCmd({
|
|
482
497
|
func: this.handleAppVersionControl,
|
|
483
498
|
args: [payload, txId],
|
|
@@ -485,7 +500,7 @@ export class DeviceAgentCloudConnection {
|
|
|
485
500
|
txId
|
|
486
501
|
});
|
|
487
502
|
if (completed) {
|
|
488
|
-
this.
|
|
503
|
+
this.txnMgr.completeTransaction(txId);
|
|
489
504
|
}
|
|
490
505
|
} catch (e) {
|
|
491
506
|
logger.error(`Error processing application install request: ${e}!`);
|
|
@@ -502,9 +517,11 @@ export class DeviceAgentCloudConnection {
|
|
|
502
517
|
case keyMirrors.toDeviceAgentMessageType.app_install_response: {
|
|
503
518
|
const payload = message.payload;
|
|
504
519
|
const { projectId, appReleaseHash } = payload.appInstallResponse;
|
|
505
|
-
if (txId !== this.
|
|
520
|
+
if (txId !== this.txnMgr.getTransactionFromProject(projectId)) {
|
|
506
521
|
throw new Error(
|
|
507
|
-
`App install response received a message for a transaction ID ${txId} that is not currently underway (${this.
|
|
522
|
+
`App install response received a message for a transaction ID ${txId} that is not currently underway (${this.txnMgr.getTransactionFromProject(
|
|
523
|
+
projectId
|
|
524
|
+
)})!`
|
|
508
525
|
);
|
|
509
526
|
}
|
|
510
527
|
const completed = await this.atomicCmd({
|
|
@@ -514,7 +531,7 @@ export class DeviceAgentCloudConnection {
|
|
|
514
531
|
txId
|
|
515
532
|
});
|
|
516
533
|
if (completed) {
|
|
517
|
-
this.
|
|
534
|
+
this.txnMgr.completeTransaction(txId);
|
|
518
535
|
}
|
|
519
536
|
|
|
520
537
|
break;
|
|
@@ -524,9 +541,11 @@ export class DeviceAgentCloudConnection {
|
|
|
524
541
|
// atomicCmd should be able to read it from the installed app
|
|
525
542
|
const payload = message.payload;
|
|
526
543
|
const { projectId } = payload.modelsInstallResponse;
|
|
527
|
-
if (txId !== this.
|
|
544
|
+
if (txId !== this.txnMgr.getTransactionFromProject(projectId)) {
|
|
528
545
|
throw new Error(
|
|
529
|
-
`Model install response received a message for a transaction ID ${txId} that is not currently underway (${this.
|
|
546
|
+
`Model install response received a message for a transaction ID ${txId} that is not currently underway (${this.txnMgr.getTransactionFromProject(
|
|
547
|
+
projectId
|
|
548
|
+
)})!`
|
|
530
549
|
);
|
|
531
550
|
}
|
|
532
551
|
const completed = await this.atomicCmd({
|
|
@@ -536,11 +555,40 @@ export class DeviceAgentCloudConnection {
|
|
|
536
555
|
txId
|
|
537
556
|
});
|
|
538
557
|
if (completed) {
|
|
539
|
-
this.
|
|
558
|
+
this.txnMgr.completeTransaction(txId);
|
|
540
559
|
}
|
|
541
560
|
|
|
542
561
|
break;
|
|
543
562
|
}
|
|
563
|
+
case keyMirrors.toDeviceAgentMessageType.device_action: {
|
|
564
|
+
try {
|
|
565
|
+
const successStatusResponsePayload = await getStatusResponsePayload(
|
|
566
|
+
keyMirrors.statusResponse.success,
|
|
567
|
+
''
|
|
568
|
+
);
|
|
569
|
+
const successStatusResponseMessage = await buildStatusResponseMessage(
|
|
570
|
+
successStatusResponsePayload,
|
|
571
|
+
txId
|
|
572
|
+
);
|
|
573
|
+
this.publisher.publishToClient(successStatusResponseMessage);
|
|
574
|
+
|
|
575
|
+
await this.handleDeviceAction(message.payload);
|
|
576
|
+
} catch (e) {
|
|
577
|
+
logger.error(
|
|
578
|
+
`There was a problem performing device action '${message.payload.action}': ${e.message}`
|
|
579
|
+
);
|
|
580
|
+
const failureStatusResponsePayload = await getStatusResponsePayload(
|
|
581
|
+
keyMirrors.statusResponse.failure,
|
|
582
|
+
e.message
|
|
583
|
+
);
|
|
584
|
+
const failureStatusResponseMessage = await buildStatusResponseMessage(
|
|
585
|
+
failureStatusResponsePayload,
|
|
586
|
+
txId
|
|
587
|
+
);
|
|
588
|
+
this.publisher.publishToClient(failureStatusResponseMessage);
|
|
589
|
+
}
|
|
590
|
+
break;
|
|
591
|
+
}
|
|
544
592
|
default:
|
|
545
593
|
logger.error(
|
|
546
594
|
`Invalid client message: '${JSON.stringify(
|
|
@@ -559,7 +607,6 @@ export class DeviceAgentCloudConnection {
|
|
|
559
607
|
logger.debug(
|
|
560
608
|
`Received message: ${JSON.stringify({ topic, message }, null, 2)}`
|
|
561
609
|
);
|
|
562
|
-
const txId = message.txId || generateTxId(); // txId should be passed in for DeviceAgentMessage messages but shadow updates won't have this
|
|
563
610
|
switch (topic) {
|
|
564
611
|
case this.shadowHandler.shadowTopics.projects.getAccepted:
|
|
565
612
|
case this.shadowHandler.shadowTopics.projects.updateDelta: {
|
|
@@ -569,26 +616,23 @@ export class DeviceAgentCloudConnection {
|
|
|
569
616
|
clientToken: message.clientToken
|
|
570
617
|
});
|
|
571
618
|
if (shadowUpdates.length) {
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
try {
|
|
619
|
+
for (const shadowUpdate of shadowUpdates) {
|
|
620
|
+
const projectId = shadowUpdate.projectId;
|
|
621
|
+
const txId = shadowUpdate.txId;
|
|
576
622
|
try {
|
|
577
|
-
this.
|
|
623
|
+
this.txnMgr.addTransaction(txId, projectId);
|
|
578
624
|
const completed = await this.atomicCmd({
|
|
579
|
-
func: this.
|
|
580
|
-
args: [
|
|
625
|
+
func: this.handleAppConfigUpdate,
|
|
626
|
+
args: [shadowUpdate, txId],
|
|
581
627
|
projectId,
|
|
582
628
|
txId
|
|
583
629
|
});
|
|
584
630
|
if (completed) {
|
|
585
|
-
this.
|
|
631
|
+
this.txnMgr.completeTransaction(txId);
|
|
586
632
|
}
|
|
587
633
|
} catch (e) {
|
|
588
|
-
logger.error(`Error
|
|
634
|
+
logger.error(`Error handling shadow message: ${e.message}`);
|
|
589
635
|
}
|
|
590
|
-
} catch (e) {
|
|
591
|
-
logger.error(`Error handling shadow message: ${e.message}`);
|
|
592
636
|
}
|
|
593
637
|
}
|
|
594
638
|
break;
|