Rules Hub
Coding Rules Library
Rule priority, scope & exceptions
Use this to align rules with the senior-level structure (P0/P1/P2, scope, exceptions/tradeoffs).
Track backfill/batch job progress with an explicit processed flag
Mark each row processed after an attempt (success or empty result), don't infer completion from whether the target field ended up populated.
Bad example
| 1 | const targets = await repo.find({ where: { email: IsNull() } }); |
| 2 | for (const row of targets) { |
| 3 | row.email = (await fetchUpstream(row)).email ?? null; |
| 4 | await repo.save(row); |
| 5 | } |
Explanation (EN)
If the upstream lookup legitimately has no email for a row, `email` stays null and the row is selected again on every future run, redoing work forever for rows that will never resolve.
Objašnjenje (HR)
Ako dohvat s izvora legitimno nema email za redak, `email` ostaje null i redak se ponovno bira na svakom sljedecem pokretanju, sto zauvijek ponavlja posao za retke koji se nikad nece rijesiti.
Good example
| 1 | const targets = await repo.find({ where: { processed: false } }); |
| 2 | for (const row of targets) { |
| 3 | row.email = (await fetchUpstream(row)).email ?? null; |
| 4 | row.processed = true; // mark attempted regardless of outcome |
| 5 | await repo.save(row); |
| 6 | } |
Explanation (EN)
An explicit `processed` boolean records that the row was attempted, independent of the result. Only genuinely transient failures (thrown errors) should leave `processed` false for retry.
Objašnjenje (HR)
Eksplicitni `processed` boolean biljezi da je redak obraden, neovisno o rezultatu. Samo stvarno privremeni neuspjesi (bacene greske) trebaju ostaviti `processed` na false radi ponovnog pokusaja.
Notes (EN)
Applies to any backfill/migration job that derives its work queue from a nullable field it's populating — the null state is ambiguous between 'not yet attempted' and 'attempted, no data available'.
Bilješke (HR)
Vrijedi za svaki backfill/migracijski posao koji izvodi red cekanja iz nullable polja koje popunjava — null stanje je dvosmisleno izmedu 'jos nije pokusano' i 'pokusano, podaci nisu dostupni'.