@@ -4,6 +4,7 @@ import { type NextRequest, NextResponse } from 'next/server'
44import { z } from 'zod'
55import { checkSessionOrInternalAuth } from '@/lib/auth/hybrid'
66import { generateRequestId } from '@/lib/core/utils/request'
7+ import { withRouteHandler } from '@/lib/core/utils/with-route-handler'
78import { getRowById , updateRow } from '@/lib/table'
89import type { RowData , WorkflowCellValue } from '@/lib/table'
910import { accessError , checkAccess } from '@/app/api/table/utils'
@@ -21,11 +22,11 @@ interface RouteParams {
2122
2223/**
2324 * POST /api/table/[tableId]/rows/[rowId]/run-workflow-column
24- * Manually (re-)runs a workflow column for a specific row. Bypasses the scheduler's
25- * eligibility predicate — `runWorkflowColumn` writes the cell to `running` as its first
26- * step, clearing any prior output/error state .
25+ * Manually (re-)runs a workflow column for a specific row by force-resetting
26+ * the cell to `pending`. The `updateRow` call fires the scheduler which
27+ * enqueues the cell job .
2728 */
28- export async function POST ( request : NextRequest , { params } : RouteParams ) {
29+ export const POST = withRouteHandler ( async ( request : NextRequest , { params } : RouteParams ) => {
2930 const requestId = generateRequestId ( )
3031 const { tableId, rowId } = await params
3132
@@ -60,16 +61,10 @@ export async function POST(request: NextRequest, { params }: RouteParams) {
6061 }
6162
6263 const executionId = generateId ( )
63- const workflowId = column . workflowConfig . workflowId
64-
65- // Force the cell back to a non-terminal state so the scheduler's
66- // eligibility check picks it up. Calling `updateRow` here also fires
67- // `scheduleWorkflowColumnRuns(table, [row])` from inside the service,
68- // which enqueues a `workflow-column-execution` job for this cell.
6964 const pendingCell : WorkflowCellValue = {
7065 executionId,
7166 jobId : null ,
72- workflowId,
67+ workflowId : column . workflowConfig . workflowId ,
7368 status : 'pending' ,
7469 output : null ,
7570 error : null ,
@@ -92,7 +87,7 @@ export async function POST(request: NextRequest, { params }: RouteParams) {
9287 { status : 400 }
9388 )
9489 }
95- logger . error ( `[ ${ requestId } ] run-workflow-column failed for ${ tableId } /${ rowId } :` , error )
90+ logger . error ( `run-workflow-column failed for ${ tableId } /${ rowId } :` , error )
9691 return NextResponse . json ( { error : 'Failed to run workflow column' } , { status : 500 } )
9792 }
98- }
93+ } )
0 commit comments