Skip to content

Commit e026bdf

Browse files
committed
ack comments
1 parent fe401f2 commit e026bdf

File tree

2 files changed

+67
-1
lines changed
  • apps/sim/app/api
    • cron/cleanup-stale-executions
    • workflows/[id]/deployments/[version]

2 files changed

+67
-1
lines changed

apps/sim/app/api/cron/cleanup-stale-executions/route.ts

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,33 @@ export async function GET(request: NextRequest) {
108108
})
109109
}
110110

111+
// Clean up stale pending jobs (never started, e.g., due to server crash before startJob())
112+
let stalePendingJobsMarkedFailed = 0
113+
114+
try {
115+
const stalePendingJobs = await db
116+
.update(asyncJobs)
117+
.set({
118+
status: JOB_STATUS.FAILED,
119+
completedAt: new Date(),
120+
error: `Job terminated: stuck in pending state for more than ${STALE_THRESHOLD_MINUTES} minutes (never started)`,
121+
updatedAt: new Date(),
122+
})
123+
.where(
124+
and(eq(asyncJobs.status, JOB_STATUS.PENDING), lt(asyncJobs.createdAt, staleThreshold))
125+
)
126+
.returning({ id: asyncJobs.id })
127+
128+
stalePendingJobsMarkedFailed = stalePendingJobs.length
129+
if (stalePendingJobsMarkedFailed > 0) {
130+
logger.info(`Marked ${stalePendingJobsMarkedFailed} stale pending jobs as failed`)
131+
}
132+
} catch (error) {
133+
logger.error('Failed to clean up stale pending jobs:', {
134+
error: error instanceof Error ? error.message : String(error),
135+
})
136+
}
137+
111138
// Delete completed/failed jobs older than retention period
112139
const retentionThreshold = new Date(Date.now() - JOB_RETENTION_HOURS * 60 * 60 * 1000)
113140
let asyncJobsDeleted = 0
@@ -144,7 +171,8 @@ export async function GET(request: NextRequest) {
144171
thresholdMinutes: STALE_THRESHOLD_MINUTES,
145172
},
146173
asyncJobs: {
147-
staleMarkedFailed: asyncJobsMarkedFailed,
174+
staleProcessingMarkedFailed: asyncJobsMarkedFailed,
175+
stalePendingMarkedFailed: stalePendingJobsMarkedFailed,
148176
oldDeleted: asyncJobsDeleted,
149177
staleThresholdMinutes: STALE_THRESHOLD_MINUTES,
150178
retentionHours: JOB_RETENTION_HOURS,

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

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,10 +261,48 @@ export async function PATCH(
261261
context: 'activate',
262262
})
263263

264+
// Apply name/description updates if provided alongside activation
265+
let updatedName: string | null | undefined
266+
let updatedDescription: string | null | undefined
267+
if (name !== undefined || description !== undefined) {
268+
const activationUpdateData: { name?: string; description?: string | null } = {}
269+
if (name !== undefined) {
270+
activationUpdateData.name = name
271+
}
272+
if (description !== undefined) {
273+
activationUpdateData.description = description
274+
}
275+
276+
const [updated] = await db
277+
.update(workflowDeploymentVersion)
278+
.set(activationUpdateData)
279+
.where(
280+
and(
281+
eq(workflowDeploymentVersion.workflowId, id),
282+
eq(workflowDeploymentVersion.version, versionNum)
283+
)
284+
)
285+
.returning({
286+
name: workflowDeploymentVersion.name,
287+
description: workflowDeploymentVersion.description,
288+
})
289+
290+
if (updated) {
291+
updatedName = updated.name
292+
updatedDescription = updated.description
293+
logger.info(
294+
`[${requestId}] Updated deployment version ${version} metadata during activation`,
295+
{ name: activationUpdateData.name, description: activationUpdateData.description }
296+
)
297+
}
298+
}
299+
264300
return createSuccessResponse({
265301
success: true,
266302
deployedAt: result.deployedAt,
267303
warnings: triggerSaveResult.warnings,
304+
...(updatedName !== undefined && { name: updatedName }),
305+
...(updatedDescription !== undefined && { description: updatedDescription }),
268306
})
269307
}
270308

0 commit comments

Comments
 (0)