processCimaLorryInoutReports
Version: Draft — Changes pending production deployment.
Overview
A cron job that picks up queued tasks to parse uploaded CIMA Lorry In/Out Report files.
On success, it triggers the next step in Flow A by creating an
Auto Update CIMA Supplier Data By Supplier Data task.
| Function | processCimaLorryInoutReports |
| Task Code | Process CIMA Lorry In_Out Report |
| Schedule | Every |
| Source File | src/_cron/cron.service.ts |
Changelog
| Date | Author | Description |
|---|---|---|
| 2026-02-25 | sf | Changed schedule from every 2 hours to every 10 minutes; changed from bulk pickup (all Pending at once) to 1 task per run via pessimistic lock (getTaskToProcess); task status update moved to finally block |
| 2026-02-25 | sf | Changed schedule from EVERY_10_SECONDS to every 2 hours (0 */2 * * *) |
Previous versions are preserved in Page Revisions (top-right menu → Revisions).
Current Logic
Schedule
(every 0 */2 * * *EVERY_10_MINUTES210 hours)minutes)
Processing Flow
Every 210 hoursminutes
│
└─ Fetch ALL Pending tasks where code = getTaskToProcess('Process CIMA Lorry In_Out Report') ← pessimistic lock, 1 task per run
└─ If noneno task → return early
│
└─ Bulk mark all fetched tasks → Running
│
└─ For each task:
│
├─ Parse value: { cima_lorry_in_out_report_id }
├│
└─ Find CimaLorryInOutReport by id
│ └─ If not found → skip (no status update, no error logged)
│found:
├─ Call cimaLorryInOutReportService.processCimaLorryInOutReport(inOutReport)
│ └─ Parses file → populates CimaDeliveryInfo records
│
├─ On success (result = true):
│ ├─ Mark task → 'Success'
│ └─ Creates MicroserviceTask:
│ code: 'Auto Update CIMA Supplier Data By Supplier Data'
│ (picked up by autoUpdateCIMASupplierDataBySupplierData on next 10-min run)
│
└─ On failure (result = false or exception)false):
└─ Markstatus → 'Fail'
│
└─ finally: update task status → 'Success' or 'Fail'
Task Input
{ "cima_lorry_in_out_report_id": 123 }
Notes
Tasks are bulk-markedUsesRunninggetTaskToProcessbefore(pessimisticthelock,loopSKIP LOCKED) —notsafeper-task.toIfrunthe server crashes mid-loop, remaining tasks stay asRunningand are never retried.concurrently.IfExactlyCimaLorryInOutReportrecord is not found, the1 task issilentlyprocessedskippedperwithcronnorun.statusRemainingupdatepending(staystasksareRunningindefinitely).picked up on the next tick.- On success, immediately chains to
autoUpdateCIMASupplierDataBySupplierDatavia a new microservice task.