1
0
Fork 0
mirror of synced 2024-08-27 07:51:37 +12:00

Minor updates to the context system and also adding env vars to automation context.

This commit is contained in:
mike12345567 2023-01-16 16:47:59 +00:00
parent 10d1455b35
commit 5e68a4d814
6 changed files with 15 additions and 6 deletions

View file

@ -147,6 +147,7 @@ export async function preview(ctx: any) {
parameters,
transformer,
queryId,
// have to pass down to the thread runner - can't put into context now
environmentVariables: envVars,
ctx: {
user: ctx.user,
@ -233,6 +234,7 @@ async function execute(
parameters: enrichedParameters,
transformer: query.transformer,
queryId: ctx.params.queryId,
// have to pass down to the thread runner - can't put into context now
environmentVariables: envVars,
ctx: {
user: ctx.user,

View file

@ -24,6 +24,7 @@ export interface TriggerOutput {
export interface AutomationContext extends AutomationResults {
steps: any[]
env?: Record<string, string>
trigger: any
}

View file

@ -10,7 +10,7 @@ async function enrichDatasourceWithValues(datasource: Datasource) {
const processed = processObjectSync(cloned, env)
return {
datasource: processed as Datasource,
envVars: env.env as Record<string, string>,
envVars: env as Record<string, string>,
}
}

View file

@ -10,7 +10,7 @@ export async function enrichContext(
return enrichedQuery
}
const env = await getEnvironmentVariables()
const parameters = { ...inputs, ...env }
const parameters = { ...inputs, env }
// enrich the fields with dynamic parameters
for (let key of Object.keys(fields)) {
if (fields[key] == null) {

View file

@ -12,5 +12,5 @@ export async function getEnvironmentVariables() {
envVars = await environmentVariables.fetchValues(appEnv)
}
return { env: envVars }
return envVars
}

View file

@ -16,7 +16,6 @@ import { storeLog } from "../automations/logging"
import { Automation, AutomationStep, AutomationStatus } from "@budibase/types"
import {
LoopStep,
LoopStepType,
LoopInput,
TriggerOutput,
AutomationContext,
@ -26,6 +25,7 @@ import { WorkerCallback } from "./definitions"
import { context, logging } from "@budibase/backend-core"
import { processObject } from "@budibase/string-templates"
import { cloneDeep } from "lodash/fp"
import * as sdkUtils from "../sdk/utils"
import env from "../environment"
const FILTER_STEP_ID = actions.ACTION_DEFINITIONS.FILTER.stepId
const LOOP_STEP_ID = actions.ACTION_DEFINITIONS.LOOP.stepId
@ -221,6 +221,8 @@ class Orchestrator {
}
async execute() {
// this will retrieve from context created at start of thread
this._context.env = await sdkUtils.getEnvironmentVariables()
let automation = this._automation
let stopped = false
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.")
}
await context.doInAppContext(appId, async () => {
const automationOrchestrator = new Orchestrator(job)
await automationOrchestrator.stopCron("stalled")
const envVars = await sdkUtils.getEnvironmentVariables()
// put into automation thread for whole context
await context.doInEnvironmentContext(envVars, async () => {
const automationOrchestrator = new Orchestrator(job)
await automationOrchestrator.stopCron("stalled")
})
})
}