(
runId: string,
status: CopilotRunStatus,
updates: {
completedAt?: Date | null
error?: string | null
requestContext?: Record<string, unknown>
} = {}
)
| 111 | } |
| 112 | |
| 113 | export async function updateRunStatus( |
| 114 | runId: string, |
| 115 | status: CopilotRunStatus, |
| 116 | updates: { |
| 117 | completedAt?: Date | null |
| 118 | error?: string | null |
| 119 | requestContext?: Record<string, unknown> |
| 120 | } = {} |
| 121 | ) { |
| 122 | return withDbSpan( |
| 123 | TraceSpan.CopilotAsyncRunsUpdateRunStatus, |
| 124 | 'UPDATE', |
| 125 | 'copilot_runs', |
| 126 | { |
| 127 | [TraceAttr.RunId]: runId, |
| 128 | [TraceAttr.CopilotRunStatus]: status, |
| 129 | [TraceAttr.CopilotRunHasError]: !!updates.error, |
| 130 | [TraceAttr.CopilotRunHasCompletedAt]: !!updates.completedAt, |
| 131 | }, |
| 132 | async () => { |
| 133 | const [run] = await db |
| 134 | .update(copilotRuns) |
| 135 | .set({ |
| 136 | status, |
| 137 | completedAt: updates.completedAt, |
| 138 | error: updates.error, |
| 139 | requestContext: updates.requestContext, |
| 140 | updatedAt: new Date(), |
| 141 | }) |
| 142 | .where(eq(copilotRuns.id, runId)) |
| 143 | .returning() |
| 144 | return run ?? null |
| 145 | } |
| 146 | ) |
| 147 | } |
| 148 | |
| 149 | async function getLatestRunForExecution(executionId: string) { |
| 150 | return withDbSpan( |
no test coverage detected