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