Rules Hub
Code Ruleset
Rule priority, scope & exceptions
Use this to align rules with the senior-level structure (P0/P1/P2, scope, exceptions/tradeoffs).
Keep optional warmup off the readiness path
Keep optional warmup off the readiness path; await initialization required for correct request handling.
Bad example
| 1 | async onModuleInit(): Promise<void> { |
| 2 | // Awaited before app.listen(): delays readiness; a throw aborts bootstrap |
| 3 | await this.populateFromUpstream(); |
| 4 | } |
Explanation (EN)
Awaiting optional slow warmup delays availability even when the service could safely serve without it.
Objašnjenje (HR)
Čekanje neobaveznog sporog warmupa odgađa dostupnost i kada bi servis mogao sigurno raditi bez njega.
Good example
| 1 | onModuleInit(): void { |
| 2 | // Fire-and-forget so bootstrap completes regardless of outcome |
| 3 | void this.populateFromUpstream().catch((err) => { |
| 4 | this.logger.error('Startup populate failed', err); |
| 5 | }); |
| 6 | } |
Explanation (EN)
Detaching the work and attaching a catch lets the server start listening immediately, and any failure is logged instead of aborting bootstrap.
Objašnjenje (HR)
Odvajanje posla i dodavanje catch-a omogućuje serveru da odmah počne slušati, a svaki kvar se logira umjesto da prekine pokretanje.
Notes (EN)
Classify startup work as a readiness prerequisite or optional warmup; only optional work can run after the service becomes ready.
Exceptions / Tradeoffs (EN)
Required initialization must finish successfully before serving dependent requests. Background jobs still need cancellation, bounded concurrency, failure reporting and shutdown coordination.
Iznimke / Tradeoffi (HR)
Obavezna inicijalizacija mora uspjeti prije posluživanja zahtjeva koji o njoj ovise. Pozadinski posao i dalje treba otkazivanje, ograničenu konkurentnost, prijavu kvarova i usklađeno gašenje.