> ## 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.

# Collection Project History Failures

`projectHistoryFailures` lưu một tài liệu cho mỗi dự án mà project-history không xử lý được các cập nhật lịch sử, hoặc đã bắt đầu resync cho dự án đó. Tài liệu bị xóa lại ngay khi việc xử lý thành công. project-history ghi nó trong `services/project-history/app/js/ErrorRecorder.js`; kiểu của nó nằm trong `services/project-history/app/js/mongo-types.ts:3-24`. Web cũng có schema Mongoose cho nó (`services/web/app/src/models/ProjectHistoryFailure.mjs:5-19`), nhưng không có mã web nào dùng model đó.

#### Các trường

| Trường | Kiểu | Ý nghĩa | Nguồn |
| - | - | - | - |
| `_id` | ObjectId | Được tạo bởi upsert. | `ErrorRecorder.js:45-60` |
| `project_id` | String | Id dự án, lưu dưới dạng chuỗi, không phải ObjectId. | `ErrorRecorder.js:46`, `mongo-types.ts:5` |
| `error` | String | Lỗi gần nhất, dạng `error.toString()`. | `ErrorRecorder.js:37` |
| `stack` | String | Stack của lỗi gần nhất. | `ErrorRecorder.js:38` |
| `queueSize` | Number | Các cập nhật đang chờ trong hàng đợi Redis của dự án tại lỗi gần nhất (`services/project-history/app/js/UpdatesProcessor.js:375`); `-1` khi lỗi đến từ việc bắt đầu resync (`services/project-history/app/js/SyncManager.js:75`, `96`). | `ErrorRecorder.js:36` |
| `ts` | Date | Thời điểm lỗi gần nhất. | `ErrorRecorder.js:39` |
| `attempts` | Number | Số lỗi đã ghi nhận kể từ khi tạo tài liệu. | `ErrorRecorder.js:49` |
| `history` | Array of Object | 10 sự kiện gần nhất, mới nhất trước: bản ghi lỗi `{ queueSize, error, stack, ts }` và các lần bắt đầu resync `{ resyncStartedAt }`. | `ErrorRecorder.js:50-56`, `92-98` |
| `resyncStartedAt` | Date | Thời điểm bắt đầu lần resync gần nhất. | `ErrorRecorder.js:90` |
| `resyncAttempts` | Number | Số lần resync đã bắt đầu kể từ khi tạo tài liệu. | `ErrorRecorder.js:91` |
| `forceDebug` | Boolean | Được đặt bởi project-history `POST /project/:project_id/force` (`?clear=true` đặt nó thành `false`). Khi `true`, lỗi ops-out-of-order trong chunk đã lưu được ghi log và bỏ qua (`UpdatesProcessor.js:574-592`). | `ErrorRecorder.js:72-82` |
| `requestCount` | Number | Có trong schema của web (`ProjectHistoryFailure.mjs:16`). Chỉ `ErrorRecorder.getLastFailure` tăng nó, và không có gì gọi hàm đó. | `ErrorRecorder.js:131-138` |

#### Ai ghi

| Mã | Chức năng |
| - | - |
| `services/project-history/app/js/ErrorRecorder.js:34-66` | `record`: upsert lỗi, `attempts` +1, thêm mục vào `history`. Được gọi khi xử lý cập nhật của dự án thất bại (`UpdatesProcessor.js:91`, `169`, `242`, `293`, `345`) và khi không thể bắt đầu resync (`SyncManager.js:75`, `96`). |
| `ErrorRecorder.js:86-102` | `recordSyncStart`: upsert, `resyncStartedAt`, `resyncAttempts` +1, thêm mục vào `history`, mỗi lần bắt đầu resync (`SyncManager.js:104`). |
| `ErrorRecorder.js:68-70` | `clearError`: xóa tài liệu sau một lần flush thành công (`UpdatesProcessor.js:101`, `194`, `259`, `355`), khi project-history `DELETE /project/:project_id` (`services/project-history/app/js/HttpController.js:1386`), và với id dự án không hợp lệ trong lúc thử lại (`services/project-history/app/js/RetryManager.js:161`). |
| `ErrorRecorder.js:72-82` | `setForceDebug`: upsert `forceDebug` (`HttpController.js:1016-1035`, route tại `services/project-history/app/js/Router.js:82`). |
| `ErrorRecorder.js:109-119` | `cloneFailure`: sao chép tài liệu sang dự án khác, cho project-history `POST /project/:project_id/clone` (`HttpController.js:135`), route mà không có gì trong web gọi. |

#### Ai đọc

| Mã | Chức năng |
| - | - |
| `RetryManager.js:113-126` | Tải mọi lỗi cho các cron job thử lại (`server-ce/config/crontab-history`, project-history `POST /retry/failures`). Job soft xử lý lại hàng đợi; job hard resync dự án, dưới dạng hard resync khi `resyncAttempts` tối thiểu là 1 và lỗi không phải là một resync đang chạy (`RetryManager.js:30-31`, `35-56`, `106-111`). |
| `services/project-history/app/js/FlushManager.js:73-82` | Việc flush mọi dự án bỏ qua các dự án có lỗi. |
| `UpdatesProcessor.js:578-592` | Đọc `forceDebug`. |
| `ErrorRecorder.js:124-129`, `140-145` | `getFailureRecord` và `getFailedProjects`: được dùng bởi `GET /project/:project_id/debug-info` (`HttpController.js:571`) và `GET /status/failures`, `GET /status/failures-full` (`Router.js:88-90`). |

#### Chỉ mục

| Tên | Khóa | Tùy chọn | Migration |
| - | - | - | - |
| `project_id_1` | `{ project_id: 1 }` | | `tools/migrations/20190912145018_create_projectHistoryFailures_indexes.mjs` |

#### Ghi chú

* Tài liệu tồn tại cho đến khi một lần flush của dự án thành công hoặc dự án bị xóa (`clearError` ở trên), nên mỗi tài liệu đánh dấu một dự án mà lần flush hoặc resync gần nhất vẫn chưa thành công.
* Các chuỗi lỗi bắt đầu bằng `OError:` được trả về dưới dạng `Error:` (`ErrorRecorder.js:18-26`); giá trị đã lưu không thay đổi.


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