* Dispatches a background filter-delete for an already-claimed job slot, * mirroring the delete-async route. Same release-on-failed-dispatch guard as * dispatchImportJob.
(params: {
jobId: string
tableId: string
workspaceId: string
filter: Filter
cutoff: Date
maxRows?: number
})
| 158 | * {@link dispatchImportJob}. |
| 159 | */ |
| 160 | async function dispatchDeleteJob(params: { |
| 161 | jobId: string |
| 162 | tableId: string |
| 163 | workspaceId: string |
| 164 | filter: Filter |
| 165 | cutoff: Date |
| 166 | maxRows?: number |
| 167 | }): Promise<void> { |
| 168 | const { jobId, tableId, workspaceId, filter, cutoff, maxRows } = params |
| 169 | if (isTriggerDevEnabled) { |
| 170 | try { |
| 171 | const [{ tableDeleteTask }, { tasks }, { resolveTriggerRegion }] = await Promise.all([ |
| 172 | import('@/background/table-delete'), |
| 173 | import('@trigger.dev/sdk'), |
| 174 | import('@/lib/core/async-jobs/region'), |
| 175 | ]) |
| 176 | await tasks.trigger<typeof tableDeleteTask>( |
| 177 | 'table-delete', |
| 178 | { jobId, tableId, workspaceId, filter, cutoff: cutoff.toISOString(), maxRows }, |
| 179 | { tags: [`tableId:${tableId}`, `jobId:${jobId}`], region: await resolveTriggerRegion() } |
| 180 | ) |
| 181 | } catch (error) { |
| 182 | await releaseJobClaim(tableId, jobId).catch(() => {}) |
| 183 | throw error |
| 184 | } |
| 185 | } else { |
| 186 | runDetached('table-delete', () => |
| 187 | runTableDelete({ jobId, tableId, workspaceId, filter, cutoff, maxRows }).catch( |
| 188 | async (error) => { |
| 189 | await markTableDeleteFailed(tableId, jobId, error) |
| 190 | throw error |
| 191 | } |
| 192 | ) |
| 193 | ) |
| 194 | } |
| 195 | } |
| 196 | |
| 197 | /** |
| 198 | * Dispatches a background bulk update for an already-claimed job slot, mirroring |
no test coverage detected