Skip to main content

Count case retention cleanup

Deletes closed count cases, with their lineage, and old counter records once they are past the closed-case retention window. Count Governance (Package C).

At a glance​

Batch classMGCWardenCountRetention (caption Warden count retention)
Menu itemMGCWardenCountRetentionMenuItem, label Count case retention cleanup
Menu pathSystem administration → Setup → Count case retention cleanup
Who may run itMGCWardenPolicyAuthorPriv (Update grant) → MGCWardenPolicyAuthoringDuty → Warden guard administrator (MGCWardenGuardAdministrator), plus the platform's System administrator. The Warden count supervisor role does not get it. Also callable over the batch API as MGCWardenBatchService.runCountRetention, behind the same menu item
Feature toggleNone. The class does not test MGCWardenCountGovFeature, so it does not stand down: it purges with Count Governance off
Company scopePer legal entity. It reads its own company's parameters and purges its own company's rows
Scheduled by defaultNo. Nothing in the product creates a batch job for it
RecurrenceYou choose. No recurrence is stated in code or docs
Setup-gap rules that watch itNone

Purpose and business justification​

Count cases and counter records name the people who counted and reviewed. Keeping them for ever is neither necessary nor, for personal data, defensible. A retention window sets when a closed case goes. The counter log (MGCWardenCountWorkerLog, who counted which work line) would otherwise grow with every counting pass for ever (method summary on purgeWorkerLog).

Two guards keep what is still live:

  • a closed case whose MISSING-queue entry is not yet settled (WrittenOff or Resolved) is kept, because stock is still sitting in the MISSING location;
  • a counter record is kept while any count case still points at its work, because the different-worker recount gate reads it at take time.

How and when it is triggered​

  • Scheduled batch job, created by an administrator from the menu item's dialog. Nothing schedules it out of the box.
  • Run now from the menu item. canRunInNewSession() returns true, so an interactive run is marshalled to a second session for the same user.
  • Batch API: MGCWardenBatchService.runCountRetention. Its summary warns: "THIS DELETES DATA."

Configuration and scheduling options​

Dialog. No fields. pack() returns conNull(); the dialog shows only the standard batch tab.

Parameter (System administration → Setup → Count governance parameters, MGCWardenCountParameters, one row per legal entity):

FieldLabelDefaultEffect
ClosedCaseRetentionDaysClosed case retention (days)365 (initValue)The window for both purges. 0 switches both purges off and keeps everything. Bounded to 0 - 36525 on write

The window is measured from the case's CreatedDateTime, not from the day it closed. A case opened 400 days ago and closed yesterday is purged on the next run under the default window.

Choosing a recurrence. The trade-off is between how long a row outlives its window and how much each run deletes. A run deletes everything past the window in one transaction per purge, so an infrequent schedule makes for larger transactions. A first run on an estate that has never run it deletes the whole backlog at once.

Batch group. No guidance in code.

What it does​

run()
|- purgeClosedCases() one transaction
| window <= 0? -> return
| for each Closed case created before (now - window):
| unsettled MISSING entry? (read past XDS) -> keep, skip
| delete its lineage rows (skipDeleteMethod + doDelete)
| delete the case
| info "N closed case(s) purged"
|- purgeWorkerLog() one transaction
window <= 0? -> return
delete counter records created before (now - window)
with no count case whose OriginWorkId is the record's work (past XDS)
info "N counter record(s) purged"
  1. Closed cases (purgeClosedCases). Cutoff is utcNow() minus ClosedCaseRetentionDays. Candidates are MGCWardenCountCase rows in status Closed created before the cutoff. Open cases are never candidates, and MGCWardenCountCase.delete() refuses one anyway.
    • Missing-entry guard. A MGCWardenMissingQueueEntry for the case in any state other than WrittenOff or Resolved keeps the case. The read runs inside unchecked(Uncheck::XDS), so a data security policy that hides the entry from the batch account cannot make it look absent .
    • Lineage. MGCWardenCountLineage.delete() throws ("Count case lineage carries Part 11 traceability and cannot be deleted"). This task is the single sanctioned deleter: it sets skipDeleteMethod(true) and calls doDelete() for the purged case's lineage rows only.
    • The case row itself deletes through its normal delete().
  2. Counter records (purgeWorkerLog). Same cutoff, on MGCWardenCountWorkerLog.CreatedDateTime, with a notexists join to MGCWardenCountCase on OriginWorkId == WorkId. The whole loop runs inside unchecked(Uncheck::XDS).

Transaction boundaries. Two transactions, one per purge. The case purge commits before the counter purge starts, so a failure in the second leaves the first done.

Error handling. The class has no try/catch. Any failure rolls back the purge in progress and escapes run(); a scheduled task then ends in error.

Concurrency. Not in MGCWardenBatchOverlapGuard's population. Two overlapping runs are not refused; each purge is one transaction over forupdate reads, so a concurrent loser rolls back rather than deleting twice (MGCWardenBatchService class summary), and may then read as failed.

Idempotency. A re-run deletes only what is still past the window and unguarded. Running it twice in a row deletes nothing the second time.

Dependencies and prerequisites​

  • The count parameters row for the company. MGCWardenCountParameters::find() creates it on first use with the initValue defaults, so a company that never opened the parameters page purges on the 365-day default.
  • Nothing else. Count Governance does not need to be on.

Inputs and outputs​

DirectionTableWhat
ReadsMGCWardenCountParametersClosedCaseRetentionDays
Reads (past XDS)MGCWardenMissingQueueEntryThe missing-entry guard
DeletesMGCWardenCountCaseClosed cases past the window, unless guarded
DeletesMGCWardenCountLineageThe purged cases' lineage
DeletesMGCWardenCountWorkerLogCounter records past the window whose work backs no case
Infolog"Warden count retention: N closed case(s) purged." and "… N counter record(s) purged." (each printed only when the window is above zero)

It writes no event-log row, no execution exception and no run record. The governance event-log rows about each case are not touched; they live on the evidence retention window and are removed by Warden retention cleanup.

MGCWardenCountCase declares no delete actions, so a purged case's rows in MGCWardenCountJournalQueue and MGCWardenMissingQueueEntry are left pointing at nothing. Warden retention cleanup removes them later, but only once a queue row is Posted or a missing entry is settled (purgeOrphanedCountQueueEntries, purgeOrphanedMissingEntries).

Logging and monitoring​

  • Batch job history: the two info lines are the only record of what was deleted.
  • Counting passes by worker (System administration → Setup → Counting passes by worker) and Count case lineage (System administration → Setup → Count case lineage) show what remains.
  • No setup-gap rule reports an unscheduled or failing count retention.

Errors, recovery and troubleshooting​

What happenedWhat you seeRecovery
Window is 0No info lines; nothing deletedIntended: retention is off
A delete failed in the case purgeTask in error; no case deleted in that runRead the batch log, fix the cause, re-run
A delete failed in the counter purgeTask in error; the case purge's line is present and its deletes standRe-run; the case purge finds nothing new
A case you expected to go is still thereCheck its status (only Closed goes), its CreatedDateTime against the window, and whether its MISSING entry is still Quarantined or Aged

Re-running is always safe: every delete is decided again from the current data.

Impact on other functionality​

  • Evidence and reports. Once a case is purged its lineage is gone with it. The count KPI entities and tiles count only cases that still exist, so a period older than the window no longer gives true rates (USER_GUIDE §7).
  • Different-worker recount gate. Unaffected while a case exists: the counter record behind it is kept.
  • Erasure. An erasure request for a worker is deferred until their count cases and counter records leave this window. MGCWardenErasurePreconditions.caseLapseOn computes that date on this batch's rule (CreatedDateTime plus the company's window; never for a case that is not closed). See Erasure execution.
  • Locks. Each purge holds one transaction over every row it deletes, for the length of the purge.
  • When it does not run, closed cases and counter records simply accumulate past the window. Nothing is blocked.