ILLDEV-463 Add batch action cleanup - #692
Conversation
There was a problem hiding this comment.
Pull request overview
This PR adds retention-based cleanup for batch action “run” events so the event table doesn’t grow indefinitely per scheduled batch task, and centralizes an int -> int32 clamping helper in broker/common.
Changes:
- Add a new SQLC query + scheduler repo method to delete old batch action runs beyond a configurable retention limit.
- Wire
SchedRepointoBatchActionServiceand invoke cleanup before dispatching the batch action handler. - Move
ToInt32clamping helper intobroker/commonand update call sites.
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| broker/test/service/supplierlocator_test.go | Switches int→int32 conversion to common.ToInt32. |
| broker/sqlc/event_query.sql | Adds DeleteOldBatchActionRunEvents query for retention cleanup. |
| broker/service/supplierlocator.go | Uses common.ToInt32 and removes local helper. |
| broker/scheduler/service/batch_action.go | Adds retention env var, injects scheduler repo, and performs cleanup before dispatch. |
| broker/scheduler/service/batch_action_test.go | Updates constructor calls and adds tests for cleanup behavior. |
| broker/scheduler/db/repo.go | Exposes DeleteOldBatchActionRunEvents on SchedRepo and implements it. |
| broker/README.md | Documents BATCH_ACTION_RUN_RETENTION env var and reflows the env table. |
| broker/common/common.go | Adds shared ToInt32 clamping helper. |
| broker/app/app.go | Creates schedRepo once and wires it into BatchActionService and scheduler API/scheduler startup. |
Comments suppressed due to low confidence (1)
broker/scheduler/service/batch_action_test.go:186
- This test mutates the package-global BATCH_ACTION_RUN_RETENTION and resets it to 5, which may not be the original value (it can be overridden via env). Capture the original value and restore it via t.Cleanup to avoid leaking state across tests.
BATCH_ACTION_RUN_RETENTION = 0
status, result := svc.batchAction(testCtx, requestAgingEvent("cql.allRecords=1", map[string]any{"interval": "24h"}))
assert.Equal(t, events.EventStatusSuccess, status)
assert.NotNil(t, result)
assert.False(t, cleanupRepo.called)
assert.True(t, repo.listCalled)
BATCH_ACTION_RUN_RETENTION = 5
|
@JanisSaldabols it makes sense to leave the invoke-background-action events since they will be cleaned up when we clean up (archive) patron requests. Let's just clean up the parent field for this event so that we don't have dangling reference when the parent invoke-batch-action event is cleaned up. |
jakub-id
left a comment
There was a problem hiding this comment.
Approving with the above change request.
6cef2e1 to
b6db822
Compare
No description provided.