@balena/open-balena-api 30.1.1-build-renovate-valkey-valkey-8-x-3691ce1b05ba7dbd8c799cc8cd785f88a7b5e52f-1 → 30.1.1-build-var-trigger-update-fb9d7df999b3cd9259d01a14060909f6d135f448-1
Sign up to get free protection for your applications and to get access to all the features.
@@ -2,6 +2,7 @@ import { sbvrUtils, hooks } from '@balena/pinejs';
|
|
2
2
|
import _ from 'lodash';
|
3
3
|
import { captureException } from '../../../infra/error-handling/index.js';
|
4
4
|
import { postDevices } from '../../device-proxy/device-proxy.js';
|
5
|
+
import { setTimeout } from 'timers/promises';
|
5
6
|
// Postgresql uses 16 bits to address the binds of sql commands. We use a number a bit below
|
6
7
|
// that limit to chunk the binds, in order to have some extra room for other things like
|
7
8
|
// computed terms/permissions.
|
@@ -39,16 +40,31 @@ const addEnvHooks = (resource, buildFilter) => {
|
|
39
40
|
}
|
40
41
|
};
|
41
42
|
const envVarHook = {
|
42
|
-
POSTRUN:
|
43
|
-
const { req, request
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
43
|
+
POSTRUN: (args) => {
|
44
|
+
const { req, request } = args;
|
45
|
+
// Send the update requests in a separate read tx so that the writer has less work to do.
|
46
|
+
args.tx.on('end', async () => {
|
47
|
+
let devices = request.custom.affectedDevices;
|
48
|
+
if (devices == null) {
|
49
|
+
// Since we use a new read transaction, we also add an artificial delay
|
50
|
+
// to make sure that the committed data have propagated to the readers.
|
51
|
+
// W/o this there would be a chance for POSTs to never trigger device updates
|
52
|
+
// in case the replication lag is high enough.
|
53
|
+
await setTimeout(1000);
|
54
|
+
devices = await sbvrUtils.db.readTransaction(async (tx) => {
|
55
|
+
return await getAffectedDeviceIds({
|
56
|
+
...args,
|
57
|
+
api: sbvrUtils.api.resin.clone({
|
58
|
+
passthrough: { req, tx },
|
59
|
+
}),
|
60
|
+
tx,
|
61
|
+
});
|
62
|
+
});
|
63
|
+
}
|
64
|
+
if (!devices || devices.length === 0) {
|
65
|
+
// If we have no devices affected then no point triggering an update.
|
66
|
+
return;
|
67
|
+
}
|
52
68
|
try {
|
53
69
|
await postDevices({
|
54
70
|
url: '/v1/update',
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"vars-update-trigger.js","sourceRoot":"","sources":["../../../../src/features/vars-schema/hooks/vars-update-trigger.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AAClD,OAAO,CAAC,MAAM,QAAQ,CAAC;AAGvB,OAAO,EAAE,gBAAgB,EAAE,MAAM,wCAAwC,CAAC;AAE1E,OAAO,EAAE,WAAW,EAAE,MAAM,oCAAoC,CAAC;
|
1
|
+
{"version":3,"file":"vars-update-trigger.js","sourceRoot":"","sources":["../../../../src/features/vars-schema/hooks/vars-update-trigger.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AAClD,OAAO,CAAC,MAAM,QAAQ,CAAC;AAGvB,OAAO,EAAE,gBAAgB,EAAE,MAAM,wCAAwC,CAAC;AAE1E,OAAO,EAAE,WAAW,EAAE,MAAM,oCAAoC,CAAC;AAEjE,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAM7C,4FAA4F;AAC5F,wFAAwF;AACxF,8BAA8B;AAC9B,uIAAuI;AACvI,MAAM,kBAAkB,GAAG,CAAC,IAAI,EAAE,GAAG,CAAC,GAAG,GAAG,CAAC;AAE7C,iBAAiB;AACjB,MAAM,WAAW,GAAG,CACnB,QAAW,EACX,WAWC,EACM,EAAE;IACT,MAAM,oBAAoB,GAAG,KAAK,EACjC,IAEC,EACA,EAAE;QACH,IAAI,CAAC;YACJ,MAAM,MAAM,GAAG,MAAM,WAAW,CAAC,IAAI,CAAC,CAAC;YACvC,IAAI,MAAM,IAAI,IAAI,EAAE,CAAC;gBACpB,OAAO;YACR,CAAC;YACD,MAAM,OAAO,GAAG,KAAK,CAA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M,EAAE,GAAG;gCACX,KAAK,EAAE;oCACN,CAAC,EAAE;wCACF,aAAa,EAAE;4CACd,IAAI,EAAE;gDACL,MAAM,EAAE,IAAI;gDACZ,KAAK,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,aAAa,EAAE,EAAE;6CAClD;yCACD;qCACD;iCACD;6BACD;yBACD;qBACD;iBACD;aACD;SACD,CAAC;IACH,CAAC;IAED,MAAM,SAAS,GAAG,MAAM,SAAS,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC;IACvD,IAAI,SAAS,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAC5B,OAAO;IACR,CAAC;IACD,OAAO;QACN,SAAS;QACT,CAAC,cAAc,EAAE,EAAE,CAAC,CAAC;YACpB,aAAa,EAAE;gBACd,IAAI,EAAE;oBACL,MAAM,EAAE,IAAI;oBACZ,KAAK,EAAE;wBACN,eAAe,EAAE;4BAChB,IAAI,EAAE;gCACL,MAAM,EAAE,GAAG;gCACX,KAAK,EAAE;oCACN,CAAC,EAAE;wCACF,aAAa,EAAE;4CACd,IAAI,EAAE;gDACL,MAAM,EAAE,IAAI;gDACZ,KAAK,EAAE;oDACN,EAAE,EAAE;wDACH,0BAA0B,EAAE;4DAC3B,IAAI,EAAE;gEACL,MAAM,EAAE,GAAG;gEACX,KAAK,EAAE,EAAE,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,GAAG,EAAE,cAAc,EAAE,EAAE,EAAE;6DAC7C;yDACD;qDACD;iDACD;6CACD;yCACD;qCACD;iCACD;6BACD;yBACD;qBACD;iBACD;aACD;SACD,CAAC;KACF,CAAC;AACH,CAAC,CAAC,CAAC"}
|
package/package.json
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"name": "@balena/open-balena-api",
|
3
3
|
"description": "Internet of things, Made Simple",
|
4
|
-
"version": "30.1.1-build-
|
4
|
+
"version": "30.1.1-build-var-trigger-update-fb9d7df999b3cd9259d01a14060909f6d135f448-1",
|
5
5
|
"license": "AGPL-3.0",
|
6
6
|
"repository": {
|
7
7
|
"type": "git",
|
@@ -167,6 +167,6 @@
|
|
167
167
|
"loader": "ts-node/esm/transpile-only"
|
168
168
|
},
|
169
169
|
"versionist": {
|
170
|
-
"publishedAt": "2024-10-
|
170
|
+
"publishedAt": "2024-10-24T13:23:00.052Z"
|
171
171
|
}
|
172
172
|
}
|