Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ensure job cancellation selection holds a lock #67

Merged
merged 1 commit into from
Nov 17, 2024

Conversation

maxcountryman
Copy link
Owner

Since we select and then update a set of tasks in a transaction in order to cancel pending tasks relative to a given job, we should also hold a lock over that selection via for update.

@maxcountryman
Copy link
Owner Author

@kirillsalykin this should ensure the selected rows are locked as per your suggestion. This could probably be done more efficiently via a single update or e.g. if mark_cancelled took &[&TaskId].

Since we select and then update a set of tasks in a transaction in order
to cancel pending tasks relative to a given job, we should also hold a
lock over that selection via `for update`.
@kirillsalykin
Copy link

Indeed, probably having one update would be more efficient and wouldnt require a lock.

@kirillsalykin
Copy link

wdyt about just having cancel all by job_id, queue_name and status = pending?

I would be happy to do this change , seems small enough so i can finish :)

@maxcountryman
Copy link
Owner Author

wdyt about just having cancel all by job_id, queue_name and status = pending?

It's probably a better approach. 🙂

The reason it wasn't implemented that way is because the queue encapsulates task life cycle. I want to avoid that leaking into other concepts as much as we can.

So maybe we should refactor mark_cancelled to take arbitrary selection criteria for the update (so we can pass through e.g. job_id).

@maxcountryman
Copy link
Owner Author

I'm going to merge this for the sake of correctness but we can come back to this at any point and improve it (it likely isn't a breaking change).

@maxcountryman maxcountryman merged commit a3febe0 into main Nov 17, 2024
4 checks passed
@maxcountryman maxcountryman deleted the job-cancel-for-update branch November 17, 2024 15:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants