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

Added QueueJob RunUntilEmptyAsync TimeSpan Overload, refactored cancellation tokens #302

Merged
merged 1 commit into from
Jul 22, 2024

Conversation

niemyjski
Copy link
Member

This should generally speed up tests where you don't want to wait the full 30 second default timeout.

linkedCancellationTokenSource.CancelAfter(acquireTimeout);

// NOTE: This has to be awaited otherwise the linkedCancellationTokenSource cancel timer will not fire.
await job.RunUntilEmptyAsync(linkedCancellationTokenSource.Token);
Copy link
Member Author

Choose a reason for hiding this comment

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

NOTE: this was initially just returning the task, which did not dispose of the cancellation token but DID prevent the cancellation token timer from firing.... This was a huge time sink to track down.

Copy link
Member Author

Choose a reason for hiding this comment

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

using (var timeoutCancellationTokenSource = new CancellationTokenSource(30000))
using (var linkedCancellationToken = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken, timeoutCancellationTokenSource.Token))
using var linkedCancellationTokenSource = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken);
linkedCancellationTokenSource.CancelAfter(TimeSpan.FromSeconds(30));
Copy link
Member Author

Choose a reason for hiding this comment

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

This seems more explicit about the behaviors and scoping of parent tokens.

@niemyjski niemyjski merged commit 0f4e865 into master Jul 22, 2024
3 checks passed
@niemyjski niemyjski deleted the feature/queue-job-run-until-empty-overload branch July 22, 2024 15:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants