Type updates for automation jobs
This commit is contained in:
parent
0cf7d4ab9c
commit
42f472b038
|
@ -9,7 +9,7 @@ import { checkTestFlag } from "../utilities/redis"
|
|||
import * as utils from "./utils"
|
||||
import env from "../environment"
|
||||
import { context, db as dbCore } from "@budibase/backend-core"
|
||||
import { Automation, Row } from "@budibase/types"
|
||||
import { Automation, Row, AutomationData, AutomationJob } from "@budibase/types"
|
||||
|
||||
export const TRIGGER_DEFINITIONS = definitions
|
||||
const JOB_OPTS = {
|
||||
|
@ -109,14 +109,16 @@ export async function externalTrigger(
|
|||
}
|
||||
params.fields = coercedFields
|
||||
}
|
||||
const data: Record<string, any> = { automation, event: params }
|
||||
|
||||
const data: AutomationData = { automation, event: params as any }
|
||||
if (getResponses) {
|
||||
data.event = {
|
||||
...data.event,
|
||||
appId: context.getAppId(),
|
||||
automation,
|
||||
}
|
||||
return utils.processEvent({ data })
|
||||
const job = { data } as AutomationJob
|
||||
return utils.processEvent(job)
|
||||
} else {
|
||||
return automationQueue.add(data, JOB_OPTS)
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { AutomationResults, AutomationStep, Document } from "@budibase/types"
|
||||
import { AutomationResults, AutomationStep } from "@budibase/types"
|
||||
|
||||
export enum LoopStepType {
|
||||
ARRAY = "Array",
|
||||
|
@ -28,6 +28,3 @@ export interface AutomationContext extends AutomationResults {
|
|||
trigger: any
|
||||
}
|
||||
|
||||
export interface AutomationMetadata extends Document {
|
||||
errorCount?: number
|
||||
}
|
||||
|
|
|
@ -13,13 +13,12 @@ import { generateAutomationMetadataID, isProdAppID } from "../db/utils"
|
|||
import { definitions as triggerDefs } from "../automations/triggerInfo"
|
||||
import { AutomationErrors, MAX_AUTOMATION_RECURRING_ERRORS } from "../constants"
|
||||
import { storeLog } from "../automations/logging"
|
||||
import { Automation, AutomationStep, AutomationStatus } from "@budibase/types"
|
||||
import { Automation, AutomationStep, AutomationStatus, AutomationMetadata, AutomationJob } from "@budibase/types"
|
||||
import {
|
||||
LoopStep,
|
||||
LoopInput,
|
||||
TriggerOutput,
|
||||
AutomationContext,
|
||||
AutomationMetadata,
|
||||
} from "../definitions/automations"
|
||||
import { WorkerCallback } from "./definitions"
|
||||
import { context, logging } from "@budibase/backend-core"
|
||||
|
@ -60,11 +59,11 @@ class Orchestrator {
|
|||
_job: Job
|
||||
executionOutput: AutomationContext
|
||||
|
||||
constructor(job: Job) {
|
||||
let automation = job.data.automation,
|
||||
triggerOutput = job.data.event
|
||||
constructor(job: AutomationJob) {
|
||||
let automation = job.data.automation
|
||||
let triggerOutput = job.data.event
|
||||
const metadata = triggerOutput.metadata
|
||||
this._chainCount = metadata ? metadata.automationChainCount : 0
|
||||
this._chainCount = metadata ? metadata.automationChainCount! : 0
|
||||
this._appId = triggerOutput.appId as string
|
||||
this._job = job
|
||||
const triggerStepId = automation.definition.trigger.stepId
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
import { EnvironmentVariablesDecrypted } from "@budibase/types"
|
||||
|
||||
export type WorkerCallback = (error: any, response?: any) => void
|
||||
|
||||
export interface QueryEvent {
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
import workerFarm from "worker-farm"
|
||||
import env from "../environment"
|
||||
import { AutomationJob } from "@budibase/types"
|
||||
import { QueryEvent } from "./definitions"
|
||||
|
||||
export const ThreadType = {
|
||||
QUERY: "query",
|
||||
|
@ -64,11 +66,11 @@ export class Thread {
|
|||
)
|
||||
}
|
||||
|
||||
run(data: any) {
|
||||
run(job: AutomationJob | QueryEvent) {
|
||||
const timeout = this.timeoutMs
|
||||
return new Promise((resolve, reject) => {
|
||||
function fire(worker: any) {
|
||||
worker.execute(data, (err: any, response: any) => {
|
||||
worker.execute(job, (err: any, response: any) => {
|
||||
if (err && err.type === "TimeoutError") {
|
||||
reject(
|
||||
new Error(`Query response time exceeded ${timeout}ms timeout.`)
|
||||
|
|
|
@ -177,3 +177,8 @@ export type AutomationStepInput = {
|
|||
appId: string
|
||||
apiKey?: string
|
||||
}
|
||||
|
||||
export interface AutomationMetadata extends Document {
|
||||
errorCount?: number
|
||||
automationChainCount?: number
|
||||
}
|
|
@ -0,0 +1,15 @@
|
|||
import { Automation, AutomationMetadata } from "../../documents"
|
||||
import { Job } from "bull"
|
||||
|
||||
export interface AutomationDataEvent {
|
||||
appId?: string
|
||||
metadata?: AutomationMetadata
|
||||
automation?: Automation
|
||||
}
|
||||
|
||||
export interface AutomationData {
|
||||
event: AutomationDataEvent
|
||||
automation: Automation
|
||||
}
|
||||
|
||||
export type AutomationJob = Job<AutomationData>
|
|
@ -1,3 +1,4 @@
|
|||
export * from "./automations"
|
||||
export * from "./hosting"
|
||||
export * from "./context"
|
||||
export * from "./events"
|
||||
|
|
Loading…
Reference in New Issue