From 47abb35a22670dc735ec825006449574ae7d3eaa Mon Sep 17 00:00:00 2001 From: Waleed Latif Date: Wed, 19 Feb 2025 13:19:28 -0800 Subject: [PATCH] fix(starter): add temp logging to debug executor inability to resolve envvars --- app/api/scheduled/execute/route.ts | 44 ++++++++++++++++++++++++++++-- 1 file changed, 42 insertions(+), 2 deletions(-) diff --git a/app/api/scheduled/execute/route.ts b/app/api/scheduled/execute/route.ts index dd8fe4113..ee49dfd58 100644 --- a/app/api/scheduled/execute/route.ts +++ b/app/api/scheduled/execute/route.ts @@ -242,11 +242,31 @@ export async function POST(req: NextRequest) { Promise.resolve({} as Record>) ) + // Create a map of decrypted environment variables + const decryptedEnvVars: Record = {} + for (const [key, encryptedValue] of Object.entries(variables)) { + try { + const { decrypted } = await decryptSecret(encryptedValue) + decryptedEnvVars[key] = decrypted + } catch (error: any) { + console.error(`Failed to decrypt ${key}:`, error) + throw new Error(`Failed to decrypt environment variable "${key}": ${error.message}`) + } + } + + // Add logging for the final block states + console.log('Final block states:', JSON.stringify(currentBlockStates, null, 2)) + // Serialize and execute the workflow const serializedWorkflow = new Serializer().serializeWorkflow(mergedStates, edges, loops) - const executor = new Executor(serializedWorkflow, currentBlockStates, {}) + console.log('Serialized workflow:', JSON.stringify(serializedWorkflow, null, 2)) + + const executor = new Executor(serializedWorkflow, currentBlockStates, decryptedEnvVars) const executionId = uuidv4() + console.log('Starting execution with ID:', executionId) + const result = await executor.execute(schedule.workflowId) + console.log('Execution result:', result) // Log the execution result await persistLog({ @@ -408,11 +428,31 @@ export async function GET(req: NextRequest) { Promise.resolve({} as Record>) ) + // Create a map of decrypted environment variables + const decryptedEnvVars: Record = {} + for (const [key, encryptedValue] of Object.entries(variables)) { + try { + const { decrypted } = await decryptSecret(encryptedValue) + decryptedEnvVars[key] = decrypted + } catch (error: any) { + console.error(`Failed to decrypt ${key}:`, error) + throw new Error(`Failed to decrypt environment variable "${key}": ${error.message}`) + } + } + + // Add logging for the final block states + console.log('Final block states:', JSON.stringify(currentBlockStates, null, 2)) + // Serialize and execute the workflow const serializedWorkflow = new Serializer().serializeWorkflow(mergedStates, edges, loops) - const executor = new Executor(serializedWorkflow, currentBlockStates, {}) + console.log('Serialized workflow:', JSON.stringify(serializedWorkflow, null, 2)) + + const executor = new Executor(serializedWorkflow, currentBlockStates, decryptedEnvVars) const executionId = uuidv4() + console.log('Starting execution with ID:', executionId) + const result = await executor.execute(schedule.workflowId) + console.log('Execution result:', result) // Log the execution result await persistLog({