Skip to content

Commit f671ff7

Browse files
committed
fix: failed repos skipping refresh marker
Signed-off-by: Mouad BANI <mouad-mb@outlook.com>
1 parent 3ce2401 commit f671ff7

1 file changed

Lines changed: 16 additions & 1 deletion

File tree

services/apps/packages_worker/src/security-contacts/writeContacts.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
import { QueryExecutor, formatQuery } from '@crowd/data-access-layer/src/queryExecutor'
22
import { prepareBulkInsert } from '@crowd/data-access-layer/src/utils'
3+
import { getServiceChildLogger } from '@crowd/logging'
34

45
import { ProcessRepoResult, RepoPolicies, ScoredContact } from './types'
56

7+
const log = getServiceChildLogger('security-contacts')
8+
69
const CONTACT_COLUMNS = [
710
'repo_id',
811
'channel',
@@ -184,7 +187,19 @@ export async function writeContactsBatch(
184187
const ok = outcomes.filter((o): o is OkResult => o.status === 'ok')
185188

186189
for (let i = 0; i < ok.length; i += WRITE_CHUNK_SIZE) {
187-
await writeContactsChunk(qx, ok.slice(i, i + WRITE_CHUNK_SIZE))
190+
const chunk = ok.slice(i, i + WRITE_CHUNK_SIZE)
191+
try {
192+
await writeContactsChunk(qx, chunk)
193+
} catch (err) {
194+
// Isolates blast radius to this chunk: without this, one bad chunk would throw out of
195+
// the whole batch, leaving every repo's contacts_last_refreshed untouched and the sweep
196+
// stuck re-fetching + re-extracting the same batch forever instead of ever advancing.
197+
log.error(
198+
{ errMsg: (err as Error).message, repoIds: chunk.map((r) => r.repoId) },
199+
'Batched contacts write failed for chunk — marking attempted without contacts update',
200+
)
201+
attemptedOnlyIds.push(...chunk.map((r) => r.repoId))
202+
}
188203
}
189204

190205
await markReposAttempted(qx, attemptedOnlyIds)

0 commit comments

Comments
 (0)