Check the batch action is not running when removing, cascade events - #687
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR tightens scheduler/batch-action lifecycle handling by adding row-level locking for scheduled-task mutations, preventing deletion while a batch action is still queued/processing, and cleaning up batch-action-related events when a batch action is removed.
Changes:
- Add
FOR UPDATEscheduled-task fetches and use them to revalidate/serialize mutations (API mutations + stuck-task recovery). - Add queries to detect/delete batch-action events by taskId and enforce a 409 Conflict when deleting an in-progress batch action.
- Extend unit/integration tests and OpenAPI to cover the new behaviors.
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/scheduler/db/schedrepo_test.go | Adds DB-level tests for active-event detection, event cleanup, and rollback behavior. |
| broker/sqlc/sched_query.sql | Introduces GetScheduledTaskByIdForUpdate query for row-locking scheduled_task. |
| broker/sqlc/event_query.sql | Adds queries to detect active batch-action events and delete batch-action events by taskId. |
| broker/scheduler/service/scheduler.go | Revalidates “stuck” tasks under row lock before rescheduling/disabling. |
| broker/scheduler/service/scheduler_test.go | Updates scheduler tests to exercise revalidation/skip paths with updated_at + row locking. |
| broker/scheduler/db/repo.go | Exposes new repo methods for row-lock fetch and batch-action event checks/deletes. |
| broker/scheduler/api/api_handler.go | Uses row-locking + active-event checks on delete; refactors batch-action mutations into a shared helper. |
| broker/scheduler/api/api_handler_test.go | Updates mocks and adds coverage for 409 Conflict + error paths. |
| broker/oapi/open-api.yaml | Documents 409 Conflict response for deleting an in-progress batch action. |
Comments suppressed due to low confidence (1)
broker/scheduler/db/repo.go:124
events.New()is not defined in the non-generatedbroker/eventspackage, so this call likely won’t compile after sqlc generation. Call the sqlc query method on a zero-valueevents.Queriesinstead.
func (r *PgSchedRepo) DeleteBatchActionEvents(ctx common.ExtendedContext, taskID string) error {
return events.New().DeleteBatchActionEvents(ctx, r.GetConnOrTx(), taskID)
}
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.