Skip to content

Commit da04ea0

Browse files
authored
fix(subflows): added change detection for parallels, updated deploy and status schemas to match parallel/loop (#956)
1 parent d4f412a commit da04ea0

File tree

3 files changed

+43
-10
lines changed

3 files changed

+43
-10
lines changed

apps/sim/app/api/workflows/[id]/deploy/route.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -211,16 +211,19 @@ export async function POST(request: NextRequest, { params }: { params: Promise<{
211211
const config = (subflow.config as any) || {}
212212
if (subflow.type === 'loop') {
213213
loops[subflow.id] = {
214+
id: subflow.id,
214215
nodes: config.nodes || [],
215-
iterationCount: config.iterationCount || 1,
216-
iterationType: config.iterationType || 'fixed',
217-
collection: config.collection || '',
216+
iterations: config.iterations || 1,
217+
loopType: config.loopType || 'for',
218+
forEachItems: config.forEachItems || '',
218219
}
219220
} else if (subflow.type === 'parallel') {
220221
parallels[subflow.id] = {
222+
id: subflow.id,
221223
nodes: config.nodes || [],
222-
parallelCount: config.parallelCount || 2,
223-
collection: config.collection || '',
224+
count: config.count || 2,
225+
distribution: config.distribution || '',
226+
parallelType: config.parallelType || 'count',
224227
}
225228
}
226229
})

apps/sim/app/api/workflows/[id]/status/route.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,16 +57,19 @@ export async function GET(request: NextRequest, { params }: { params: Promise<{
5757
const config = (subflow.config as any) || {}
5858
if (subflow.type === 'loop') {
5959
loops[subflow.id] = {
60+
id: subflow.id,
6061
nodes: config.nodes || [],
61-
iterationCount: config.iterationCount || 1,
62-
iterationType: config.iterationType || 'fixed',
63-
collection: config.collection || '',
62+
iterations: config.iterations || 1,
63+
loopType: config.loopType || 'for',
64+
forEachItems: config.forEachItems || '',
6465
}
6566
} else if (subflow.type === 'parallel') {
6667
parallels[subflow.id] = {
68+
id: subflow.id,
6769
nodes: config.nodes || [],
68-
parallelCount: config.parallelCount || 2,
69-
collection: config.collection || '',
70+
count: config.count || 2,
71+
distribution: config.distribution || '',
72+
parallelType: config.parallelType || 'count',
7073
}
7174
}
7275
})

apps/sim/lib/workflows/utils.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,33 @@ export function hasWorkflowChanged(
313313
}
314314
}
315315

316+
// 5. Compare parallels
317+
const currentParallels = currentState.parallels || {}
318+
const deployedParallels = deployedState.parallels || {}
319+
320+
const currentParallelIds = Object.keys(currentParallels).sort()
321+
const deployedParallelIds = Object.keys(deployedParallels).sort()
322+
323+
if (
324+
currentParallelIds.length !== deployedParallelIds.length ||
325+
normalizedStringify(currentParallelIds) !== normalizedStringify(deployedParallelIds)
326+
) {
327+
return true
328+
}
329+
330+
// Compare each parallel with normalized values
331+
for (const parallelId of currentParallelIds) {
332+
const normalizedCurrentParallel = normalizeValue(currentParallels[parallelId])
333+
const normalizedDeployedParallel = normalizeValue(deployedParallels[parallelId])
334+
335+
if (
336+
normalizedStringify(normalizedCurrentParallel) !==
337+
normalizedStringify(normalizedDeployedParallel)
338+
) {
339+
return true
340+
}
341+
}
342+
316343
return false
317344
}
318345

0 commit comments

Comments
 (0)