@budibase/server 2.6.16 → 2.6.17

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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@budibase/server",
3
3
  "email": "hi@budibase.com",
4
- "version": "2.6.16",
4
+ "version": "2.6.17",
5
5
  "description": "Budibase Web Server",
6
6
  "main": "src/index.ts",
7
7
  "repository": {
@@ -45,12 +45,12 @@
45
45
  "license": "GPL-3.0",
46
46
  "dependencies": {
47
47
  "@apidevtools/swagger-parser": "10.0.3",
48
- "@budibase/backend-core": "^2.6.16",
49
- "@budibase/client": "^2.6.16",
50
- "@budibase/pro": "2.6.15",
51
- "@budibase/shared-core": "^2.6.16",
52
- "@budibase/string-templates": "^2.6.16",
53
- "@budibase/types": "^2.6.16",
48
+ "@budibase/backend-core": "^2.6.17",
49
+ "@budibase/client": "^2.6.17",
50
+ "@budibase/pro": "2.6.16",
51
+ "@budibase/shared-core": "^2.6.17",
52
+ "@budibase/string-templates": "^2.6.17",
53
+ "@budibase/types": "^2.6.17",
54
54
  "@bull-board/api": "3.7.0",
55
55
  "@bull-board/koa": "3.9.4",
56
56
  "@elastic/elasticsearch": "7.10.0",
@@ -176,5 +176,5 @@
176
176
  "optionalDependencies": {
177
177
  "oracledb": "5.3.0"
178
178
  },
179
- "gitHead": "d43a6a44bd074e077ea131303c0f7a2b0e0ddb75"
179
+ "gitHead": "2a0993fe5e3cab1ec779603cc9228f824e2cea4d"
180
180
  }
@@ -9,7 +9,7 @@ import { checkTestFlag } from "../utilities/redis"
9
9
  import * as utils from "./utils"
10
10
  import env from "../environment"
11
11
  import { context, db as dbCore } from "@budibase/backend-core"
12
- import { Automation, Row } from "@budibase/types"
12
+ import { Automation, Row, AutomationData, AutomationJob } from "@budibase/types"
13
13
 
14
14
  export const TRIGGER_DEFINITIONS = definitions
15
15
  const JOB_OPTS = {
@@ -109,14 +109,16 @@ export async function externalTrigger(
109
109
  }
110
110
  params.fields = coercedFields
111
111
  }
112
- const data: Record<string, any> = { automation, event: params }
112
+
113
+ const data: AutomationData = { automation, event: params as any }
113
114
  if (getResponses) {
114
115
  data.event = {
115
116
  ...data.event,
116
117
  appId: context.getAppId(),
117
118
  automation,
118
119
  }
119
- return utils.processEvent({ data })
120
+ const job = { data } as AutomationJob
121
+ return utils.processEvent(job)
120
122
  } else {
121
123
  return automationQueue.add(data, JOB_OPTS)
122
124
  }
@@ -8,7 +8,7 @@ import { db as dbCore, context } from "@budibase/backend-core"
8
8
  import { getAutomationMetadataParams } from "../db/utils"
9
9
  import { cloneDeep } from "lodash/fp"
10
10
  import { quotas } from "@budibase/pro"
11
- import { Automation, WebhookActionType } from "@budibase/types"
11
+ import { Automation, AutomationJob, WebhookActionType } from "@budibase/types"
12
12
  import sdk from "../sdk"
13
13
 
14
14
  const REBOOT_CRON = "@reboot"
@@ -16,27 +16,34 @@ const WH_STEP_ID = definitions.WEBHOOK.stepId
16
16
  const CRON_STEP_ID = definitions.CRON.stepId
17
17
  const Runner = new Thread(ThreadType.AUTOMATION)
18
18
 
19
- const jobMessage = (job: any, message: string) => {
20
- return `app=${job.data.event.appId} automation=${job.data.automation._id} jobId=${job.id} trigger=${job.data.automation.definition.trigger.event} : ${message}`
19
+ function loggingArgs(job: AutomationJob) {
20
+ return {
21
+ jobId: job.id,
22
+ trigger: job.data.automation.definition.trigger.event,
23
+ }
21
24
  }
22
25
 
23
- export async function processEvent(job: any) {
24
- try {
25
- const automationId = job.data.automation._id
26
- console.log(jobMessage(job, "running"))
27
- // need to actually await these so that an error can be captured properly
28
- return await context.doInContext(job.data.event.appId, async () => {
26
+ export async function processEvent(job: AutomationJob) {
27
+ const appId = job.data.event.appId!
28
+ const automationId = job.data.automation._id!
29
+ const task = async () => {
30
+ try {
31
+ // need to actually await these so that an error can be captured properly
32
+ console.log("automation running", loggingArgs(job))
33
+
29
34
  const runFn = () => Runner.run(job)
30
- return quotas.addAutomation(runFn, {
35
+ const result = await quotas.addAutomation(runFn, {
31
36
  automationId,
32
37
  })
33
- })
34
- } catch (err) {
35
- const errJson = JSON.stringify(err)
36
- console.error(jobMessage(job, `was unable to run - ${errJson}`))
37
- console.trace(err)
38
- return { err }
38
+ console.log("automation completed", loggingArgs(job))
39
+ return result
40
+ } catch (err) {
41
+ console.error(`automation was unable to run`, err, loggingArgs(job))
42
+ return { err }
43
+ }
39
44
  }
45
+
46
+ return await context.doInAutomationContext({ appId, automationId, task })
40
47
  }
41
48
 
42
49
  export async function updateTestHistory(
@@ -1,4 +1,4 @@
1
- import { AutomationResults, AutomationStep, Document } from "@budibase/types"
1
+ import { AutomationResults, AutomationStep } from "@budibase/types"
2
2
 
3
3
  export enum LoopStepType {
4
4
  ARRAY = "Array",
@@ -27,7 +27,3 @@ export interface AutomationContext extends AutomationResults {
27
27
  env?: Record<string, string>
28
28
  trigger: any
29
29
  }
30
-
31
- export interface AutomationMetadata extends Document {
32
- errorCount?: number
33
- }
@@ -13,13 +13,18 @@ import { generateAutomationMetadataID, isProdAppID } from "../db/utils"
13
13
  import { definitions as triggerDefs } from "../automations/triggerInfo"
14
14
  import { AutomationErrors, MAX_AUTOMATION_RECURRING_ERRORS } from "../constants"
15
15
  import { storeLog } from "../automations/logging"
16
- import { Automation, AutomationStep, AutomationStatus } from "@budibase/types"
16
+ import {
17
+ Automation,
18
+ AutomationStep,
19
+ AutomationStatus,
20
+ AutomationMetadata,
21
+ AutomationJob,
22
+ } from "@budibase/types"
17
23
  import {
18
24
  LoopStep,
19
25
  LoopInput,
20
26
  TriggerOutput,
21
27
  AutomationContext,
22
- AutomationMetadata,
23
28
  } from "../definitions/automations"
24
29
  import { WorkerCallback } from "./definitions"
25
30
  import { context, logging } from "@budibase/backend-core"
@@ -60,11 +65,11 @@ class Orchestrator {
60
65
  _job: Job
61
66
  executionOutput: AutomationContext
62
67
 
63
- constructor(job: Job) {
64
- let automation = job.data.automation,
65
- triggerOutput = job.data.event
68
+ constructor(job: AutomationJob) {
69
+ let automation = job.data.automation
70
+ let triggerOutput = job.data.event
66
71
  const metadata = triggerOutput.metadata
67
- this._chainCount = metadata ? metadata.automationChainCount : 0
72
+ this._chainCount = metadata ? metadata.automationChainCount! : 0
68
73
  this._appId = triggerOutput.appId as string
69
74
  this._job = job
70
75
  const triggerStepId = automation.definition.trigger.stepId
@@ -1,5 +1,3 @@
1
- import { EnvironmentVariablesDecrypted } from "@budibase/types"
2
-
3
1
  export type WorkerCallback = (error: any, response?: any) => void
4
2
 
5
3
  export interface QueryEvent {
@@ -1,5 +1,7 @@
1
1
  import workerFarm from "worker-farm"
2
2
  import env from "../environment"
3
+ import { AutomationJob } from "@budibase/types"
4
+ import { QueryEvent } from "./definitions"
3
5
 
4
6
  export const ThreadType = {
5
7
  QUERY: "query",
@@ -64,11 +66,11 @@ export class Thread {
64
66
  )
65
67
  }
66
68
 
67
- run(data: any) {
69
+ run(job: AutomationJob | QueryEvent) {
68
70
  const timeout = this.timeoutMs
69
71
  return new Promise((resolve, reject) => {
70
72
  function fire(worker: any) {
71
- worker.execute(data, (err: any, response: any) => {
73
+ worker.execute(job, (err: any, response: any) => {
72
74
  if (err && err.type === "TimeoutError") {
73
75
  reject(
74
76
  new Error(`Query response time exceeded ${timeout}ms timeout.`)