fix(execution): async executions when envvars are not set (#397)

This commit is contained in:
Waleed Latif
2025-05-21 20:15:51 -07:00
committed by GitHub
parent 0015dc93de
commit afcc66afc6
2 changed files with 10 additions and 9 deletions

View File

@@ -155,6 +155,7 @@ export async function GET(req: NextRequest) {
const mergedStates = mergeSubblockState(blocks)
// Retrieve environment variables for this user (if any).
const [userEnv] = await db
.select()
.from(environment)
@@ -162,13 +163,12 @@ export async function GET(req: NextRequest) {
.limit(1)
if (!userEnv) {
logger.error(
`[${requestId}] No environment variables found for user ${workflowRecord.userId}`
logger.debug(
`[${requestId}] No environment record found for user ${workflowRecord.userId}. Proceeding with empty variables.`
)
throw new Error('No environment variables found for this user')
}
const variables = EnvVarsSchema.parse(userEnv.variables)
const variables = EnvVarsSchema.parse(userEnv?.variables ?? {})
const currentBlockStates = await Object.entries(mergedStates).reduce(
async (accPromise, [id, block]) => {

View File

@@ -102,7 +102,7 @@ async function executeWorkflow(workflow: any, requestId: string, input?: any) {
// Use the same execution flow as in scheduled executions
const mergedStates = mergeSubblockState(blocks)
// Retrieve environment variables for this user
// Fetch the user's environment variables (if any)
const [userEnv] = await db
.select()
.from(environment)
@@ -110,12 +110,13 @@ async function executeWorkflow(workflow: any, requestId: string, input?: any) {
.limit(1)
if (!userEnv) {
logger.error(`[${requestId}] No environment variables found for user: ${workflow.userId}`)
throw new Error('No environment variables found for this user')
logger.debug(
`[${requestId}] No environment record found for user ${workflow.userId}. Proceeding with empty variables.`
)
}
// Parse and validate environment variables
const variables = EnvVarsSchema.parse(userEnv.variables)
// Parse and validate environment variables.
const variables = EnvVarsSchema.parse(userEnv?.variables ?? {})
// Replace environment variables in the block states
const currentBlockStates = await Object.entries(mergedStates).reduce(