Skip to main content

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 210 hoursminutes
Source File src/_cron/cron.service.ts

Changelog

Date Author Description
2026-02-25sfChanged 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

0 */2 * * *EVERY_10_MINUTES (every 210 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-markedUses RunninggetTaskToProcess before(pessimistic thelock, loopSKIP LOCKED)notsafe per-task.to Ifrun the server crashes mid-loop, remaining tasks stay as Running and are never retried.concurrently.
  • IfExactly CimaLorryInOutReport record is not found, the1 task is silentlyprocessed skippedper withcron norun. statusRemaining updatepending (staystasks Runningare indefinitely).picked up on the next tick.
  • On success, immediately chains to autoUpdateCIMASupplierDataBySupplierData via a new microservice task.