|
1 | 1 | import { getLogger } from "@logtape/logtape"; |
2 | | -import { and, eq, inArray, sql } from "drizzle-orm"; |
| 2 | +import { and, eq, inArray, or, sql } from "drizzle-orm"; |
3 | 3 |
|
4 | 4 | import db, { type Transaction } from "../db"; |
5 | 5 | import federation from "../federation/federation"; |
@@ -126,25 +126,30 @@ async function processJobItems( |
126 | 126 | return; |
127 | 127 | } |
128 | 128 |
|
129 | | - // Get pending items for this job with lock |
130 | | - const pendingItems = await tx |
| 129 | + // Get unfinished items for this job with lock |
| 130 | + const unfinishedItems = await tx |
131 | 131 | .select() |
132 | 132 | .from(schema.importJobItems) |
133 | 133 | .where( |
134 | 134 | and( |
135 | 135 | eq(schema.importJobItems.jobId, job.id), |
136 | | - eq(schema.importJobItems.status, "pending"), |
| 136 | + or( |
| 137 | + eq(schema.importJobItems.status, "pending"), |
| 138 | + eq(schema.importJobItems.status, "processing"), |
| 139 | + ), |
137 | 140 | ), |
138 | 141 | ) |
139 | 142 | .limit(BATCH_SIZE) |
140 | 143 | .for("update", { skipLocked: true }); |
141 | 144 |
|
142 | | - if (pendingItems.length === 0) { |
| 145 | + if (unfinishedItems.length === 0) { |
143 | 146 | // No more items - mark job as completed |
144 | 147 | await finalizeJob(tx, job, "completed"); |
145 | 148 | return; |
146 | 149 | } |
147 | 150 |
|
| 151 | + const pendingItems = unfinishedItems.filter((i) => i.status == "pending"); |
| 152 | + |
148 | 153 | // Get account owner for this job |
149 | 154 | const accountOwner = await tx.query.accountOwners.findFirst({ |
150 | 155 | where: eq(schema.accountOwners.id, job.accountOwnerId), |
|
0 commit comments