Minor updates to the context system and also adding env vars to automation context.
This commit is contained in:
parent
10d1455b35
commit
5e68a4d814
|
@ -147,6 +147,7 @@ export async function preview(ctx: any) {
|
||||||
parameters,
|
parameters,
|
||||||
transformer,
|
transformer,
|
||||||
queryId,
|
queryId,
|
||||||
|
// have to pass down to the thread runner - can't put into context now
|
||||||
environmentVariables: envVars,
|
environmentVariables: envVars,
|
||||||
ctx: {
|
ctx: {
|
||||||
user: ctx.user,
|
user: ctx.user,
|
||||||
|
@ -233,6 +234,7 @@ async function execute(
|
||||||
parameters: enrichedParameters,
|
parameters: enrichedParameters,
|
||||||
transformer: query.transformer,
|
transformer: query.transformer,
|
||||||
queryId: ctx.params.queryId,
|
queryId: ctx.params.queryId,
|
||||||
|
// have to pass down to the thread runner - can't put into context now
|
||||||
environmentVariables: envVars,
|
environmentVariables: envVars,
|
||||||
ctx: {
|
ctx: {
|
||||||
user: ctx.user,
|
user: ctx.user,
|
||||||
|
|
|
@ -24,6 +24,7 @@ export interface TriggerOutput {
|
||||||
|
|
||||||
export interface AutomationContext extends AutomationResults {
|
export interface AutomationContext extends AutomationResults {
|
||||||
steps: any[]
|
steps: any[]
|
||||||
|
env?: Record<string, string>
|
||||||
trigger: any
|
trigger: any
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -10,7 +10,7 @@ async function enrichDatasourceWithValues(datasource: Datasource) {
|
||||||
const processed = processObjectSync(cloned, env)
|
const processed = processObjectSync(cloned, env)
|
||||||
return {
|
return {
|
||||||
datasource: processed as Datasource,
|
datasource: processed as Datasource,
|
||||||
envVars: env.env as Record<string, string>,
|
envVars: env as Record<string, string>,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -10,7 +10,7 @@ export async function enrichContext(
|
||||||
return enrichedQuery
|
return enrichedQuery
|
||||||
}
|
}
|
||||||
const env = await getEnvironmentVariables()
|
const env = await getEnvironmentVariables()
|
||||||
const parameters = { ...inputs, ...env }
|
const parameters = { ...inputs, env }
|
||||||
// enrich the fields with dynamic parameters
|
// enrich the fields with dynamic parameters
|
||||||
for (let key of Object.keys(fields)) {
|
for (let key of Object.keys(fields)) {
|
||||||
if (fields[key] == null) {
|
if (fields[key] == null) {
|
||||||
|
|
|
@ -12,5 +12,5 @@ export async function getEnvironmentVariables() {
|
||||||
|
|
||||||
envVars = await environmentVariables.fetchValues(appEnv)
|
envVars = await environmentVariables.fetchValues(appEnv)
|
||||||
}
|
}
|
||||||
return { env: envVars }
|
return envVars
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,7 +16,6 @@ import { storeLog } from "../automations/logging"
|
||||||
import { Automation, AutomationStep, AutomationStatus } from "@budibase/types"
|
import { Automation, AutomationStep, AutomationStatus } from "@budibase/types"
|
||||||
import {
|
import {
|
||||||
LoopStep,
|
LoopStep,
|
||||||
LoopStepType,
|
|
||||||
LoopInput,
|
LoopInput,
|
||||||
TriggerOutput,
|
TriggerOutput,
|
||||||
AutomationContext,
|
AutomationContext,
|
||||||
|
@ -26,6 +25,7 @@ import { WorkerCallback } from "./definitions"
|
||||||
import { context, logging } from "@budibase/backend-core"
|
import { context, logging } from "@budibase/backend-core"
|
||||||
import { processObject } from "@budibase/string-templates"
|
import { processObject } from "@budibase/string-templates"
|
||||||
import { cloneDeep } from "lodash/fp"
|
import { cloneDeep } from "lodash/fp"
|
||||||
|
import * as sdkUtils from "../sdk/utils"
|
||||||
import env from "../environment"
|
import env from "../environment"
|
||||||
const FILTER_STEP_ID = actions.ACTION_DEFINITIONS.FILTER.stepId
|
const FILTER_STEP_ID = actions.ACTION_DEFINITIONS.FILTER.stepId
|
||||||
const LOOP_STEP_ID = actions.ACTION_DEFINITIONS.LOOP.stepId
|
const LOOP_STEP_ID = actions.ACTION_DEFINITIONS.LOOP.stepId
|
||||||
|
@ -221,6 +221,8 @@ class Orchestrator {
|
||||||
}
|
}
|
||||||
|
|
||||||
async execute() {
|
async execute() {
|
||||||
|
// this will retrieve from context created at start of thread
|
||||||
|
this._context.env = await sdkUtils.getEnvironmentVariables()
|
||||||
let automation = this._automation
|
let automation = this._automation
|
||||||
let stopped = false
|
let stopped = false
|
||||||
let loopStep: AutomationStep | undefined = undefined
|
let loopStep: AutomationStep | undefined = undefined
|
||||||
|
@ -474,7 +476,11 @@ export const removeStalled = async (job: Job) => {
|
||||||
throw new Error("Unable to execute, event doesn't contain app ID.")
|
throw new Error("Unable to execute, event doesn't contain app ID.")
|
||||||
}
|
}
|
||||||
await context.doInAppContext(appId, async () => {
|
await context.doInAppContext(appId, async () => {
|
||||||
const automationOrchestrator = new Orchestrator(job)
|
const envVars = await sdkUtils.getEnvironmentVariables()
|
||||||
await automationOrchestrator.stopCron("stalled")
|
// put into automation thread for whole context
|
||||||
|
await context.doInEnvironmentContext(envVars, async () => {
|
||||||
|
const automationOrchestrator = new Orchestrator(job)
|
||||||
|
await automationOrchestrator.stopCron("stalled")
|
||||||
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue