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

Add EnqueueAfter and RequeueAfter option to queue #318

Merged
1 commit merged into from
May 26, 2023
Merged

Add EnqueueAfter and RequeueAfter option to queue #318

1 commit merged into from
May 26, 2023

Conversation

ghost
Copy link

@ghost ghost commented May 23, 2023

Description

This commit adds an option for an item to be enqueued after a specified
duration. During that duration the item can not be enqueued if requested
through Enqueue to ensure that the item is not enqueued before that
duration is completed.

This allows reconcilers to delay reconciliation for an item when it
knows it will be performing an operation which takes longer than the
polling cycle preventing the poller from requeuing that item.

RequeueAfter is a wrapper around Done() followed by EnqueueAfter() done
under the same lock to prevent race condition when an item could be
requeued between Done and the EnqueueAfter call.

Also adds a new error type, RequeueAfterError, which can be returned by
a reconcile function to indicate that an item should be requeued after a
certain duration. This should only be used as an optimisation and the
pollers and reconcilers should be designed to pick up correctly from a
restart of the system.

Type of Change

[ ] Bug Fix
[ ] New Feature
[ ] Breaking Change
[X] Refactor
[ ] Documentation
[ ] Other (please describe)

Checklist

  • I have read the contributing guidelines
  • Existing issues have been referenced (where applicable)
  • I have verified this change is not present in other open pull requests
  • Functionality is documented
  • All code style checks pass
  • New code contribution is covered by automated tests
  • All new and existing tests pass

@ghost ghost changed the title Ensure that the reconcile queue tracks processing items Add EnqueueAfter and RequeueAfter option to queue May 23, 2023
This commit adds an option for an item to be enqueued after a specified
duration. During that duration the item can not be enqueued if requested
through Enqueue to ensure that the item is not enqueued before that
duration is completed.

This allows reconcilers to delay reconciliation for an item when it
knows it will be performing an operation which takes longer than the
polling cycle preventing the poller from requeuing that item.

RequeueAfter is a wrapper around Done() followed by EnqueueAfter() done
under the same lock to prevent race condition when an item could be
requeued between Done and the EnqueueAfter call.

Also adds a new error type, RequeueAfterError, which can be returned by
a reconcile function to indicate that an item should be requeued after a
certain duration. This should only be used as an optimisation and the
pollers and reconcilers should be designed to pick up correctly from a
restart of the system.
@ghost ghost marked this pull request as ready for review May 25, 2023 07:48
@ghost ghost self-requested a review as a code owner May 25, 2023 07:48
Copy link
Contributor

@chrisgacsal chrisgacsal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! :shipit:

@ghost ghost added this pull request to the merge queue May 26, 2023
Merged via the queue into main with commit 5d74f9f May 26, 2023
5 checks passed
@ghost ghost deleted the queue_requeue branch May 26, 2023 09:06
_, isProcessing := q.processing[item]
_, isWaitingForEnqueue := q.waitingForEnqueue[item]
if inQueue || isProcessing || isWaitingForEnqueue {
// item is already known by the queue so there is nothing to do
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sambetts-cisco maybe a warning is needed here, it is probably a "bug" that you try to enqueueAfter for an already known item.

This pull request was closed.
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.

None yet

3 participants