@budibase/server 2.6.16 → 2.6.18

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.
@@ -8,7 +8,7 @@
8
8
  <link rel="preconnect" href="https://fonts.gstatic.com" />
9
9
  <link href="https://fonts.googleapis.com/css2?family=Source+Sans+Pro:wght@400;600;700&display=swap"
10
10
  rel="stylesheet" />
11
- <script type="module" crossorigin src="/builder/assets/index.a40dcadd.js"></script>
11
+ <script type="module" crossorigin src="/builder/assets/index.69c5c1ea.js"></script>
12
12
  <link rel="stylesheet" href="/builder/assets/index.86c992bf.css">
13
13
  </head>
14
14
 
@@ -135,7 +135,8 @@ function externalTrigger(automation, params, { getResponses } = {}) {
135
135
  const data = { automation, event: params };
136
136
  if (getResponses) {
137
137
  data.event = Object.assign(Object.assign({}, data.event), { appId: backend_core_1.context.getAppId(), automation });
138
- return utils.processEvent({ data });
138
+ const job = { data };
139
+ return utils.processEvent(job);
139
140
  }
140
141
  else {
141
142
  return bullboard_1.automationQueue.add(data, JOB_OPTS);
@@ -29,28 +29,33 @@ const REBOOT_CRON = "@reboot";
29
29
  const WH_STEP_ID = triggerInfo_1.definitions.WEBHOOK.stepId;
30
30
  const CRON_STEP_ID = triggerInfo_1.definitions.CRON.stepId;
31
31
  const Runner = new threads_1.Thread(threads_1.ThreadType.AUTOMATION);
32
- const jobMessage = (job, message) => {
33
- return `app=${job.data.event.appId} automation=${job.data.automation._id} jobId=${job.id} trigger=${job.data.automation.definition.trigger.event} : ${message}`;
34
- };
32
+ function loggingArgs(job) {
33
+ return {
34
+ jobId: job.id,
35
+ trigger: job.data.automation.definition.trigger.event,
36
+ };
37
+ }
35
38
  function processEvent(job) {
36
39
  return __awaiter(this, void 0, void 0, function* () {
37
- try {
38
- const automationId = job.data.automation._id;
39
- console.log(jobMessage(job, "running"));
40
- // need to actually await these so that an error can be captured properly
41
- return yield backend_core_1.context.doInContext(job.data.event.appId, () => __awaiter(this, void 0, void 0, function* () {
40
+ const appId = job.data.event.appId;
41
+ const automationId = job.data.automation._id;
42
+ const task = () => __awaiter(this, void 0, void 0, function* () {
43
+ try {
44
+ // need to actually await these so that an error can be captured properly
45
+ console.log("automation running", loggingArgs(job));
42
46
  const runFn = () => Runner.run(job);
43
- return pro_1.quotas.addAutomation(runFn, {
47
+ const result = yield pro_1.quotas.addAutomation(runFn, {
44
48
  automationId,
45
49
  });
46
- }));
47
- }
48
- catch (err) {
49
- const errJson = JSON.stringify(err);
50
- console.error(jobMessage(job, `was unable to run - ${errJson}`));
51
- console.trace(err);
52
- return { err };
53
- }
50
+ console.log("automation completed", loggingArgs(job));
51
+ return result;
52
+ }
53
+ catch (err) {
54
+ console.error(`automation was unable to run`, err, loggingArgs(job));
55
+ return { err };
56
+ }
57
+ });
58
+ return yield backend_core_1.context.doInAutomationContext({ appId, automationId, task });
54
59
  });
55
60
  }
56
61
  exports.processEvent = processEvent;
@@ -76,7 +76,8 @@ function getLoopIterations(loopStep, input) {
76
76
  */
77
77
  class Orchestrator {
78
78
  constructor(job) {
79
- let automation = job.data.automation, triggerOutput = job.data.event;
79
+ let automation = job.data.automation;
80
+ let triggerOutput = job.data.event;
80
81
  const metadata = triggerOutput.metadata;
81
82
  this._chainCount = metadata ? metadata.automationChainCount : 0;
82
83
  this._appId = triggerOutput.appId;
@@ -84,11 +84,11 @@ class Thread {
84
84
  this.count === 0 ||
85
85
  environment_1.default.isInThread());
86
86
  }
87
- run(data) {
87
+ run(job) {
88
88
  const timeout = this.timeoutMs;
89
89
  return new Promise((resolve, reject) => {
90
90
  function fire(worker) {
91
- worker.execute(data, (err, response) => {
91
+ worker.execute(job, (err, response) => {
92
92
  if (err && err.type === "TimeoutError") {
93
93
  reject(new Error(`Query response time exceeded ${timeout}ms timeout.`));
94
94
  }