autoupdate: check if PR is first when running update operation #103
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.
It can happen that the Update operations is run for multiple PRs instead of only
the first one in the active queue.
An example is that multiple update operations are queued in
the go-routine pool. The first run is running for PR #1, the queued one is for PR #2.
If PR #2 gets suspended, the update operation is still queued.
When a PR is suspended the update operation is only canceled if it is
also first in the queue and has been started.
To prevent it, updatePR() now checks if the PR for that it runs is the first one
in the active queue, otherwise it does nothing.
It also now checks if it's context is canceled, in the beginning, to prevent
unnecessary function calls
A better solution would be to change the go routine pool, to be able to remove
operations for the queue via the PR identifier. This would allow to always
remove updatePR operations when a PR gets suspended.