Fixing some automation typing issues.
This commit is contained in:
parent
b2b74aa048
commit
d83bd47bd7
|
@ -177,7 +177,7 @@ export async function trigger(
|
|||
let hasCollectStep = sdk.automations.utils.checkForCollectStep(automation)
|
||||
if (hasCollectStep && (await features.isSyncAutomationsEnabled())) {
|
||||
try {
|
||||
const response: AutomationResults = await triggers.externalTrigger(
|
||||
const response = await triggers.externalTrigger(
|
||||
automation,
|
||||
{
|
||||
fields: ctx.request.body.fields,
|
||||
|
@ -188,6 +188,10 @@ export async function trigger(
|
|||
{ getResponses: true }
|
||||
)
|
||||
|
||||
if (!("steps" in response)) {
|
||||
ctx.throw(400, "Unable to collect response")
|
||||
}
|
||||
|
||||
let collectedValue = response.steps.find(
|
||||
step => step.stepId === AutomationActionStepId.COLLECT
|
||||
)
|
||||
|
|
|
@ -20,6 +20,7 @@ import {
|
|||
AutomationStatus,
|
||||
AutomationRowEvent,
|
||||
UserBindings,
|
||||
AutomationResults,
|
||||
} from "@budibase/types"
|
||||
import { executeInThread } from "../threads/automation"
|
||||
import { dataFilters, sdk } from "@budibase/shared-core"
|
||||
|
@ -32,6 +33,14 @@ const JOB_OPTS = {
|
|||
import * as automationUtils from "../automations/automationUtils"
|
||||
import { doesTableExist } from "../sdk/app/tables/getters"
|
||||
|
||||
type DidNotTriggerResponse = {
|
||||
outputs: {
|
||||
success: false
|
||||
status: AutomationStatus.STOPPED
|
||||
}
|
||||
message: AutomationStoppedReason.TRIGGER_FILTER_NOT_MET
|
||||
}
|
||||
|
||||
async function getAllAutomations() {
|
||||
const db = context.getAppDB()
|
||||
let automations = await db.allDocs<Automation>(
|
||||
|
@ -148,7 +157,7 @@ export async function externalTrigger(
|
|||
user?: UserBindings
|
||||
},
|
||||
{ getResponses }: { getResponses?: boolean } = {}
|
||||
): Promise<Record<string, any>> {
|
||||
): Promise<AutomationResults | DidNotTriggerResponse | AutomationJob> {
|
||||
if (automation.disabled) {
|
||||
throw new Error("Automation is disabled")
|
||||
}
|
||||
|
|
|
@ -26,3 +26,6 @@ export interface AutomationContext extends AutomationResults {
|
|||
company?: string
|
||||
}
|
||||
}
|
||||
|
||||
export interface AutomationResponse
|
||||
extends Omit<AutomationContext, "stepsByName" | "stepsById"> {}
|
||||
|
|
|
@ -30,7 +30,11 @@ import {
|
|||
UserBindings,
|
||||
isBasicSearchOperator,
|
||||
} from "@budibase/types"
|
||||
import { AutomationContext, TriggerOutput } from "../definitions/automations"
|
||||
import {
|
||||
AutomationContext,
|
||||
AutomationResponse,
|
||||
TriggerOutput,
|
||||
} from "../definitions/automations"
|
||||
import { WorkerCallback } from "./definitions"
|
||||
import { context, logging, configs } from "@budibase/backend-core"
|
||||
import {
|
||||
|
@ -81,7 +85,7 @@ class Orchestrator {
|
|||
private job: Job
|
||||
private loopStepOutputs: LoopStep[]
|
||||
private stopped: boolean
|
||||
private executionOutput: Omit<AutomationContext, "stepsByName" | "stepsById">
|
||||
private executionOutput: AutomationResponse
|
||||
private currentUser: UserBindings | undefined
|
||||
|
||||
constructor(job: AutomationJob) {
|
||||
|
@ -257,7 +261,7 @@ class Orchestrator {
|
|||
})
|
||||
}
|
||||
|
||||
async execute(): Promise<any> {
|
||||
async execute(): Promise<AutomationResponse | undefined> {
|
||||
return tracer.trace(
|
||||
"Orchestrator.execute",
|
||||
{ resource: "automation" },
|
||||
|
@ -723,7 +727,9 @@ export function execute(job: Job<AutomationData>, callback: WorkerCallback) {
|
|||
})
|
||||
}
|
||||
|
||||
export async function executeInThread(job: Job<AutomationData>) {
|
||||
export async function executeInThread(
|
||||
job: Job<AutomationData>
|
||||
): Promise<AutomationResponse> {
|
||||
const appId = job.data.event.appId
|
||||
if (!appId) {
|
||||
throw new Error("Unable to execute, event doesn't contain app ID.")
|
||||
|
@ -735,7 +741,7 @@ export async function executeInThread(job: Job<AutomationData>) {
|
|||
}, job.data.event.timeout || env.AUTOMATION_THREAD_TIMEOUT)
|
||||
})
|
||||
|
||||
return await context.doInAppContext(appId, async () => {
|
||||
return (await context.doInAppContext(appId, async () => {
|
||||
await context.ensureSnippetContext()
|
||||
const envVars = await sdkUtils.getEnvironmentVariables()
|
||||
// put into automation thread for whole context
|
||||
|
@ -746,7 +752,7 @@ export async function executeInThread(job: Job<AutomationData>) {
|
|||
timeoutPromise,
|
||||
])
|
||||
})
|
||||
})
|
||||
})) as AutomationResponse
|
||||
}
|
||||
|
||||
export const removeStalled = async (job: Job) => {
|
||||
|
|
Loading…
Reference in New Issue