@budibase/server 2.6.19-alpha.30 → 2.6.19-alpha.31
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/automation.js +72 -28
- package/dist/automation.js.map +3 -3
- package/dist/index.js +54 -17
- package/dist/index.js.map +3 -3
- package/dist/query.js +4 -0
- package/dist/query.js.map +2 -2
- package/package.json +9 -8
- package/src/automations/logging/index.ts +21 -0
- package/src/environment.ts +1 -0
- package/src/threads/automation.ts +45 -28
- package/src/threads/index.ts +9 -3
- package/src/threads/utils.ts +2 -0
package/dist/automation.js
CHANGED
|
@@ -128,6 +128,7 @@ var init_environment = __esm({
|
|
|
128
128
|
ENABLE_ANALYTICS: process.env.ENABLE_ANALYTICS,
|
|
129
129
|
SELF_HOSTED: process.env.SELF_HOSTED,
|
|
130
130
|
HTTP_MB_LIMIT: process.env.HTTP_MB_LIMIT,
|
|
131
|
+
FORKED_PROCESS_NAME: process.env.FORKED_PROCESS_NAME || "main",
|
|
131
132
|
// old
|
|
132
133
|
CLIENT_ID: process.env.CLIENT_ID,
|
|
133
134
|
_set(key, value) {
|
|
@@ -3647,6 +3648,7 @@ var init_logger = __esm({
|
|
|
3647
3648
|
}
|
|
3648
3649
|
const mergingObject = {
|
|
3649
3650
|
err: error,
|
|
3651
|
+
pid: process.pid,
|
|
3650
3652
|
...contextObject
|
|
3651
3653
|
};
|
|
3652
3654
|
if (objects.length) {
|
|
@@ -26770,8 +26772,10 @@ function makeVariableKey(queryId, variable) {
|
|
|
26770
26772
|
}
|
|
26771
26773
|
function threadSetup() {
|
|
26772
26774
|
if (environment_default.isTest() || environment_default.DISABLE_THREADING || !environment_default.isInThread()) {
|
|
26775
|
+
console.debug(`[${environment_default.FORKED_PROCESS_NAME}] thread setup skipped`);
|
|
26773
26776
|
return;
|
|
26774
26777
|
}
|
|
26778
|
+
console.debug(`[${environment_default.FORKED_PROCESS_NAME}] thread setup running`);
|
|
26775
26779
|
init8();
|
|
26776
26780
|
}
|
|
26777
26781
|
async function checkCacheForDynamicVariable(queryId, variable) {
|
|
@@ -26845,13 +26849,17 @@ var _Thread = class {
|
|
|
26845
26849
|
this.count = opts.count ? opts.count : 1;
|
|
26846
26850
|
this.disableThreading = this.shouldDisableThreading();
|
|
26847
26851
|
if (!this.disableThreading) {
|
|
26852
|
+
console.debug(
|
|
26853
|
+
`[${environment_default.FORKED_PROCESS_NAME}] initialising worker farm type=${type}`
|
|
26854
|
+
);
|
|
26848
26855
|
const workerOpts = {
|
|
26849
26856
|
autoStart: true,
|
|
26850
26857
|
maxConcurrentWorkers: this.count,
|
|
26851
26858
|
workerOptions: {
|
|
26852
26859
|
env: {
|
|
26853
26860
|
...process.env,
|
|
26854
|
-
FORKED_PROCESS: "1"
|
|
26861
|
+
FORKED_PROCESS: "1",
|
|
26862
|
+
FORKED_PROCESS_NAME: type
|
|
26855
26863
|
}
|
|
26856
26864
|
}
|
|
26857
26865
|
};
|
|
@@ -26861,6 +26869,10 @@ var _Thread = class {
|
|
|
26861
26869
|
}
|
|
26862
26870
|
this.workers = (0, import_worker_farm.default)(workerOpts, typeToFile(type), ["execute"]);
|
|
26863
26871
|
_Thread.workerRefs.push(this.workers);
|
|
26872
|
+
} else {
|
|
26873
|
+
console.debug(
|
|
26874
|
+
`[${environment_default.FORKED_PROCESS_NAME}] skipping worker farm type=${type}`
|
|
26875
|
+
);
|
|
26864
26876
|
}
|
|
26865
26877
|
}
|
|
26866
26878
|
shouldDisableThreading() {
|
|
@@ -26872,9 +26884,7 @@ var _Thread = class {
|
|
|
26872
26884
|
function fire(worker) {
|
|
26873
26885
|
worker.execute(job, (err, response2) => {
|
|
26874
26886
|
if (err && err.type === "TimeoutError") {
|
|
26875
|
-
reject(
|
|
26876
|
-
new Error(`Query response time exceeded ${timeout2}ms timeout.`)
|
|
26877
|
-
);
|
|
26887
|
+
reject(new Error(`Thread timeout exceeded ${timeout2}ms timeout.`));
|
|
26878
26888
|
} else if (err) {
|
|
26879
26889
|
reject(err);
|
|
26880
26890
|
} else {
|
|
@@ -31950,10 +31960,29 @@ init_constants6();
|
|
|
31950
31960
|
init_environment();
|
|
31951
31961
|
init_src4();
|
|
31952
31962
|
init_src2();
|
|
31963
|
+
var import_object_sizeof = __toESM(require("object-sizeof"));
|
|
31964
|
+
var MAX_LOG_SIZE_MB = 5;
|
|
31965
|
+
var MB_IN_BYTES = 1024 * 1024;
|
|
31966
|
+
function sanitiseResults(results) {
|
|
31967
|
+
const message = `[removed] - max results size of ${MAX_LOG_SIZE_MB}MB exceeded`;
|
|
31968
|
+
for (let step of results.steps) {
|
|
31969
|
+
step.inputs = {
|
|
31970
|
+
message
|
|
31971
|
+
};
|
|
31972
|
+
step.outputs = {
|
|
31973
|
+
message,
|
|
31974
|
+
success: step.outputs.success
|
|
31975
|
+
};
|
|
31976
|
+
}
|
|
31977
|
+
}
|
|
31953
31978
|
async function storeLog2(automation, results) {
|
|
31954
31979
|
if (environment_default.DISABLE_AUTOMATION_LOGS) {
|
|
31955
31980
|
return;
|
|
31956
31981
|
}
|
|
31982
|
+
const bytes = (0, import_object_sizeof.default)(results);
|
|
31983
|
+
if (bytes / MB_IN_BYTES > MAX_LOG_SIZE_MB) {
|
|
31984
|
+
sanitiseResults(results);
|
|
31985
|
+
}
|
|
31957
31986
|
await automations_exports.logs.storeLog(automation, results);
|
|
31958
31987
|
}
|
|
31959
31988
|
|
|
@@ -31969,8 +31998,8 @@ var FILTER_STEP_ID = BUILTIN_ACTION_DEFINITIONS.FILTER.stepId;
|
|
|
31969
31998
|
var LOOP_STEP_ID = BUILTIN_ACTION_DEFINITIONS.LOOP.stepId;
|
|
31970
31999
|
var CRON_STEP_ID2 = definitions.CRON.stepId;
|
|
31971
32000
|
var STOPPED_STATUS = { success: true, status: "stopped" /* STOPPED */ };
|
|
31972
|
-
function getLoopIterations(loopStep
|
|
31973
|
-
|
|
32001
|
+
function getLoopIterations(loopStep) {
|
|
32002
|
+
let binding = loopStep.inputs.binding;
|
|
31974
32003
|
if (!binding) {
|
|
31975
32004
|
return 0;
|
|
31976
32005
|
}
|
|
@@ -31986,7 +32015,6 @@ var Orchestrator = class {
|
|
|
31986
32015
|
constructor(job) {
|
|
31987
32016
|
let automation = job.data.automation;
|
|
31988
32017
|
let triggerOutput = job.data.event;
|
|
31989
|
-
let timeout2 = job.data.event.timeout;
|
|
31990
32018
|
const metadata = triggerOutput.metadata;
|
|
31991
32019
|
this._chainCount = metadata ? metadata.automationChainCount : 0;
|
|
31992
32020
|
this._appId = triggerOutput.appId;
|
|
@@ -32120,7 +32148,7 @@ var Orchestrator = class {
|
|
|
32120
32148
|
});
|
|
32121
32149
|
}
|
|
32122
32150
|
async execute() {
|
|
32123
|
-
var _a;
|
|
32151
|
+
var _a, _b;
|
|
32124
32152
|
this._context.env = await getEnvironmentVariables2();
|
|
32125
32153
|
let automation = this._automation;
|
|
32126
32154
|
let stopped = false;
|
|
@@ -32139,6 +32167,7 @@ var Orchestrator = class {
|
|
|
32139
32167
|
return;
|
|
32140
32168
|
}
|
|
32141
32169
|
}
|
|
32170
|
+
const start2 = performance.now();
|
|
32142
32171
|
for (let step of automation.definition.steps) {
|
|
32143
32172
|
if (timeoutFlag) {
|
|
32144
32173
|
break;
|
|
@@ -32157,20 +32186,16 @@ var Orchestrator = class {
|
|
|
32157
32186
|
}
|
|
32158
32187
|
if (loopStep) {
|
|
32159
32188
|
input = await (0, import_string_templates8.processObject)(loopStep.inputs, this._context);
|
|
32160
|
-
iterations = getLoopIterations(loopStep
|
|
32189
|
+
iterations = getLoopIterations(loopStep);
|
|
32161
32190
|
}
|
|
32162
32191
|
for (let index2 = 0; index2 < iterations; index2++) {
|
|
32163
32192
|
let originalStepInput = (0, import_fp8.cloneDeep)(step.inputs);
|
|
32164
32193
|
if (loopStep && input.binding) {
|
|
32165
|
-
let newInput = await (0, import_string_templates8.processObject)(
|
|
32166
|
-
loopStep.inputs,
|
|
32167
|
-
(0, import_fp8.cloneDeep)(this._context)
|
|
32168
|
-
);
|
|
32169
32194
|
let tempOutput = { items: loopSteps, iterations: iterationCount };
|
|
32170
32195
|
try {
|
|
32171
|
-
|
|
32196
|
+
loopStep.inputs.binding = typecastForLooping(
|
|
32172
32197
|
loopStep,
|
|
32173
|
-
|
|
32198
|
+
loopStep.inputs
|
|
32174
32199
|
);
|
|
32175
32200
|
} catch (err) {
|
|
32176
32201
|
this.updateContextAndOutput(loopStepNumber, step, tempOutput, {
|
|
@@ -32183,7 +32208,7 @@ var Orchestrator = class {
|
|
|
32183
32208
|
}
|
|
32184
32209
|
let item = [];
|
|
32185
32210
|
if (typeof loopStep.inputs.binding === "string" && loopStep.inputs.option === "String") {
|
|
32186
|
-
item = stringSplit(
|
|
32211
|
+
item = stringSplit(loopStep.inputs.binding);
|
|
32187
32212
|
} else if (Array.isArray(loopStep.inputs.binding)) {
|
|
32188
32213
|
item = loopStep.inputs.binding;
|
|
32189
32214
|
}
|
|
@@ -32326,7 +32351,18 @@ var Orchestrator = class {
|
|
|
32326
32351
|
loopSteps = [];
|
|
32327
32352
|
}
|
|
32328
32353
|
}
|
|
32329
|
-
|
|
32354
|
+
const end2 = performance.now();
|
|
32355
|
+
const executionTime = end2 - start2;
|
|
32356
|
+
console.log(`Execution time: ${executionTime} milliseconds`);
|
|
32357
|
+
try {
|
|
32358
|
+
await storeLog2(this._automation, this.executionOutput);
|
|
32359
|
+
} catch (e) {
|
|
32360
|
+
if (e.status === 413 && ((_b = e.request) == null ? void 0 : _b.data)) {
|
|
32361
|
+
delete e.request.data;
|
|
32362
|
+
e.request.data = { message: "removed due to large size" };
|
|
32363
|
+
}
|
|
32364
|
+
logging_exports.logAlert("Error writing automation log", e);
|
|
32365
|
+
}
|
|
32330
32366
|
if (isProdAppID2(this._appId) && isRecurring(automation) && metadata) {
|
|
32331
32367
|
await this.updateMetadata(metadata);
|
|
32332
32368
|
}
|
|
@@ -32335,20 +32371,28 @@ var Orchestrator = class {
|
|
|
32335
32371
|
};
|
|
32336
32372
|
function execute3(job, callback) {
|
|
32337
32373
|
const appId = job.data.event.appId;
|
|
32374
|
+
const automationId = job.data.automation._id;
|
|
32338
32375
|
if (!appId) {
|
|
32339
32376
|
throw new Error("Unable to execute, event doesn't contain app ID.");
|
|
32340
32377
|
}
|
|
32341
|
-
|
|
32342
|
-
|
|
32343
|
-
|
|
32344
|
-
|
|
32345
|
-
|
|
32346
|
-
|
|
32347
|
-
|
|
32348
|
-
|
|
32349
|
-
|
|
32350
|
-
|
|
32351
|
-
|
|
32378
|
+
if (!automationId) {
|
|
32379
|
+
throw new Error("Unable to execute, event doesn't contain automation ID.");
|
|
32380
|
+
}
|
|
32381
|
+
return context_exports.doInAutomationContext({
|
|
32382
|
+
appId,
|
|
32383
|
+
automationId,
|
|
32384
|
+
task: async () => {
|
|
32385
|
+
const envVars = await getEnvironmentVariables2();
|
|
32386
|
+
await context_exports.doInEnvironmentContext(envVars, async () => {
|
|
32387
|
+
const automationOrchestrator = new Orchestrator(job);
|
|
32388
|
+
try {
|
|
32389
|
+
const response2 = await automationOrchestrator.execute();
|
|
32390
|
+
callback(null, response2);
|
|
32391
|
+
} catch (err) {
|
|
32392
|
+
callback(err);
|
|
32393
|
+
}
|
|
32394
|
+
});
|
|
32395
|
+
}
|
|
32352
32396
|
});
|
|
32353
32397
|
}
|
|
32354
32398
|
function executeSynchronously(job) {
|