1
0
Fork 0
mirror of synced 2024-10-05 12:34:50 +13:00

Type updates for automation jobs

This commit is contained in:
Rory Powell 2023-05-17 12:26:07 +01:00
parent 0cf7d4ab9c
commit 42f472b038
8 changed files with 36 additions and 17 deletions

View file

@ -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)
}

View file

@ -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
}

View file

@ -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

View file

@ -1,5 +1,3 @@
import { EnvironmentVariablesDecrypted } from "@budibase/types"
export type WorkerCallback = (error: any, response?: any) => void
export interface QueryEvent {

View file

@ -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.`)

View file

@ -177,3 +177,8 @@ export type AutomationStepInput = {
appId: string
apiKey?: string
}
export interface AutomationMetadata extends Document {
errorCount?: number
automationChainCount?: number
}

View file

@ -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>

View file

@ -1,3 +1,4 @@
export * from "./automations"
export * from "./hosting"
export * from "./context"
export * from "./events"