> ## Documentation Index
> Fetch the complete documentation index at: https://ayakaleaf-pro.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Koleksi Project History Failures

`projectHistoryFailures` menyimpan satu dokumen per proyek yang pembaruan riwayatnya tidak dapat diproses project-history, atau yang sinkronisasi ulangnya telah dimulai. Dokumen dihapus lagi segera setelah pemrosesan berhasil. project-history menulisnya di `services/project-history/app/js/ErrorRecorder.js`; tipenya ada di `services/project-history/app/js/mongo-types.ts:3-24`. Web juga memiliki skema Mongoose untuknya (`services/web/app/src/models/ProjectHistoryFailure.mjs:5-19`), tetapi tidak ada kode web yang memakai model itu.

#### Field

| Field | Tipe | Arti | Sumber |
| - | - | - | - |
| `_id` | ObjectId | Dibuat oleh upsert. | `ErrorRecorder.js:45-60` |
| `project_id` | String | Id proyek, disimpan sebagai string, bukan ObjectId. | `ErrorRecorder.js:46`, `mongo-types.ts:5` |
| `error` | String | Error terakhir, sebagai `error.toString()`. | `ErrorRecorder.js:37` |
| `stack` | String | Stack dari error terakhir. | `ErrorRecorder.js:38` |
| `queueSize` | Number | Pembaruan yang menunggu di antrean Redis proyek saat error terakhir (`services/project-history/app/js/UpdatesProcessor.js:375`); `-1` jika error berasal dari memulai sinkronisasi ulang (`services/project-history/app/js/SyncManager.js:75`, `96`). | `ErrorRecorder.js:36` |
| `ts` | Date | Waktu error terakhir. | `ErrorRecorder.js:39` |
| `attempts` | Number | Jumlah error yang tercatat sejak dokumen dibuat. | `ErrorRecorder.js:49` |
| `history` | Array of Object | 10 peristiwa terakhir, terbaru lebih dulu: catatan error `{ queueSize, error, stack, ts }` dan awal sinkronisasi ulang `{ resyncStartedAt }`. | `ErrorRecorder.js:50-56`, `92-98` |
| `resyncStartedAt` | Date | Kapan sinkronisasi ulang terakhir dimulai. | `ErrorRecorder.js:90` |
| `resyncAttempts` | Number | Jumlah sinkronisasi ulang yang dimulai sejak dokumen dibuat. | `ErrorRecorder.js:91` |
| `forceDebug` | Boolean | Diatur oleh project-history `POST /project/:project_id/force` (`?clear=true` mengaturnya ke `false`). Selama `true`, error ops-out-of-order di chunk yang tersimpan dicatat di log dan diabaikan (`UpdatesProcessor.js:574-592`). | `ErrorRecorder.js:72-82` |
| `requestCount` | Number | Ada di skema web (`ProjectHistoryFailure.mjs:16`). Hanya `ErrorRecorder.getLastFailure` yang menaikkannya, dan tidak ada yang memanggil fungsi itu. | `ErrorRecorder.js:131-138` |

#### Siapa yang menulis

| Kode | Fungsinya |
| - | - |
| `services/project-history/app/js/ErrorRecorder.js:34-66` | `record`: upsert error, `attempts` +1, entri ditambahkan ke `history`. Dipanggil ketika pemrosesan pembaruan proyek gagal (`UpdatesProcessor.js:91`, `169`, `242`, `293`, `345`) dan ketika sinkronisasi ulang tidak dapat dimulai (`SyncManager.js:75`, `96`). |
| `ErrorRecorder.js:86-102` | `recordSyncStart`: upsert, `resyncStartedAt`, `resyncAttempts` +1, entri ditambahkan ke `history`, setiap kali sinkronisasi ulang dimulai (`SyncManager.js:104`). |
| `ErrorRecorder.js:68-70` | `clearError`: menghapus dokumen setelah flush berhasil (`UpdatesProcessor.js:101`, `194`, `259`, `355`), pada project-history `DELETE /project/:project_id` (`services/project-history/app/js/HttpController.js:1386`), dan untuk id proyek yang tidak valid saat percobaan ulang (`services/project-history/app/js/RetryManager.js:161`). |
| `ErrorRecorder.js:72-82` | `setForceDebug`: upsert `forceDebug` (`HttpController.js:1016-1035`, route di `services/project-history/app/js/Router.js:82`). |
| `ErrorRecorder.js:109-119` | `cloneFailure`: menyalin dokumen ke proyek lain, untuk project-history `POST /project/:project_id/clone` (`HttpController.js:135`), yang tidak dipanggil oleh apa pun di web. |

#### Siapa yang membaca

| Kode | Fungsinya |
| - | - |
| `RetryManager.js:113-126` | Memuat semua kegagalan untuk cron job percobaan ulang (`server-ce/config/crontab-history`, project-history `POST /retry/failures`). Job soft memproses antrean lagi; job hard menyinkronkan ulang proyek, sebagai sinkronisasi ulang hard ketika `resyncAttempts` minimal 1 dan error-nya bukan sinkronisasi ulang yang sedang berjalan (`RetryManager.js:30-31`, `35-56`, `106-111`). |
| `services/project-history/app/js/FlushManager.js:73-82` | Flush semua proyek melewati proyek yang memiliki kegagalan. |
| `UpdatesProcessor.js:578-592` | Membaca `forceDebug`. |
| `ErrorRecorder.js:124-129`, `140-145` | `getFailureRecord` dan `getFailedProjects`: dipakai oleh `GET /project/:project_id/debug-info` (`HttpController.js:571`) serta `GET /status/failures`, `GET /status/failures-full` (`Router.js:88-90`). |

#### Indeks

| Nama | Kunci | Opsi | Migrasi |
| - | - | - | - |
| `project_id_1` | `{ project_id: 1 }` | | `tools/migrations/20190912145018_create_projectHistoryFailures_indexes.mjs` |

#### Catatan

* Sebuah dokumen tetap ada sampai flush proyek berhasil atau proyek dihapus (`clearError` di atas), sehingga setiap dokumen menandai proyek yang flush atau sinkronisasi ulang terakhirnya belum berhasil.
* String error yang diawali `OError:` dikembalikan sebagai `Error:` (`ErrorRecorder.js:18-26`); nilai yang tersimpan tidak berubah.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.