(input: {
tableId: string
workspaceId: string
requestId: string
mode: DispatchMode
scope: DispatchScope
limit?: DispatchLimit | null
isManualRun: boolean
triggeredByUserId?: string | null
})
| 178 | } |
| 179 | |
| 180 | export async function insertDispatch(input: { |
| 181 | tableId: string |
| 182 | workspaceId: string |
| 183 | requestId: string |
| 184 | mode: DispatchMode |
| 185 | scope: DispatchScope |
| 186 | limit?: DispatchLimit | null |
| 187 | isManualRun: boolean |
| 188 | triggeredByUserId?: string | null |
| 189 | }): Promise<string> { |
| 190 | const id = `tdsp_${generateId().replace(/-/g, '')}` |
| 191 | await db.insert(tableRunDispatches).values({ |
| 192 | id, |
| 193 | tableId: input.tableId, |
| 194 | workspaceId: input.workspaceId, |
| 195 | requestId: input.requestId, |
| 196 | mode: input.mode, |
| 197 | scope: input.scope, |
| 198 | limit: input.limit ?? null, |
| 199 | status: 'pending', |
| 200 | // -1 = "haven't started." First window's filter `position > -1` matches |
| 201 | // position 0; subsequent iterations advance to `lastPosition` which then |
| 202 | // correctly excludes already-processed rows. |
| 203 | cursor: -1, |
| 204 | isManualRun: input.isManualRun, |
| 205 | triggeredByUserId: input.triggeredByUserId ?? null, |
| 206 | }) |
| 207 | return id |
| 208 | } |
| 209 | |
| 210 | /** Read every dispatch on a table whose status is still `pending` or |
| 211 | * `dispatching`. Drives the client-side "about to run" overlay: rows in an |
no test coverage detected