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 abort functionality to search #2370

Merged
merged 9 commits into from
Nov 21, 2024
Merged

Add abort functionality to search #2370

merged 9 commits into from
Nov 21, 2024

Conversation

awharn
Copy link
Member

@awharn awharn commented Nov 19, 2024

What It Does

Adds the ability to specify a function to tell the search functions to stop.

How to Test

Review Checklist
I certify that I have:

Additional Comments

Signed-off-by: Andrew W. Harn <[email protected]>
Copy link
Member

@t1m0thyj t1m0thyj left a comment

Choose a reason for hiding this comment

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

LGTM, thanks @awharn!

Copy link

codecov bot commented Nov 19, 2024

Codecov Report

Attention: Patch coverage is 88.88889% with 2 lines in your changes missing coverage. Please review.

Project coverage is 91.27%. Comparing base (b2ae2fb) to head (f641bb1).
Report is 12 commits behind head on master.

Files with missing lines Patch % Lines
packages/zosfiles/src/methods/search/Search.ts 88.23% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2370      +/-   ##
==========================================
- Coverage   91.27%   91.27%   -0.01%     
==========================================
  Files         636      636              
  Lines       18083    18096      +13     
  Branches     3862     3868       +6     
==========================================
+ Hits        16506    16517      +11     
- Misses       1576     1578       +2     
  Partials        1        1              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.


🚨 Try these New Features:

Signed-off-by: Andrew W. Harn <[email protected]>
Copy link
Member

@traeok traeok left a comment

Choose a reason for hiding this comment

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

Changes LGTM, thanks for adding this Andrew 👍

@@ -45,4 +45,7 @@ export interface ISearchOptions {
/* A function that, if provided, is called with a list of data sets and members that are about to be searched. */
/* If true, continue search. If false, terminate search. */
continueSearch?: (dataSets: IDataSet[]) => Promise<boolean> | boolean;

/* A function that gets called to validate whether or not to abort if a timeout isn't specified */
abortSearch?: () => boolean;
Copy link
Member

Choose a reason for hiding this comment

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

It is unclear how we expect the author of an abortSearch() callback to decide whether to return true or false.
Without that understanding, it is unclear how we expect the search to behave in various scenarios.
Perhaps you could describe the intention in a parking lot or other meeting?

Copy link
Member Author

Choose a reason for hiding this comment

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

I updated the comment to try and be more clear about the intention of the callback. In VSCode, there is a concept of a cancellation token, so in that context, the passed in callback will be () => { return token.isCancellationRequested } where that variable is a boolean reflective of if the user pressed the 'cancel' button on the progress bar UI. Effectively, the desired behavior is that the callback is checked before every search, and if the callback suddenly starts to return true, the calling function is requesting that the search operations be aborted immediately, and that further requests to the resource should cease.

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 could also be true for other extending applications, since searching hundreds or thousands of data sets or members could take a very long time, and there is no way for a calling application to stop the inner code running in an asynchronous function once it starts, unless that function provides a method to terminate it early.

Copy link
Member

Choose a reason for hiding this comment

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

Thanks for the clarification.

@@ -45,4 +45,7 @@ export interface ISearchOptions {
/* A function that, if provided, is called with a list of data sets and members that are about to be searched. */
/* If true, continue search. If false, terminate search. */
continueSearch?: (dataSets: IDataSet[]) => Promise<boolean> | boolean;

/* A function that gets called to validate whether or not to abort if a timeout isn't specified */
abortSearch?: () => boolean;
Copy link
Member

Choose a reason for hiding this comment

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

Thanks for the clarification.

Copy link
Member

@zFernand0 zFernand0 left a comment

Choose a reason for hiding this comment

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

LGTM! 😋
Thanks for clarifying the uses for abortSearch 🙏

@@ -146,6 +146,10 @@ export class Search {
searchOptions.progressTask.stageName = TaskStage.FAILED;
searchOptions.progressTask.percentComplete = 100;
searchOptions.progressTask.statusMessage = "Operation timed out";
} else if (searchOptions.abortSearch && searchOptions.abortSearch()) {
Copy link
Member

Choose a reason for hiding this comment

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

it seems that doing searchOptions.abortSearch?.() works in typescript. 🤯
(at least when using the latest version of ts-node 😋 )

Copy link
Member Author

Choose a reason for hiding this comment

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

That is both awesome and terrifying syntax. I can give it a shot.

Signed-off-by: Andrew W. Harn <[email protected]>
@t1m0thyj t1m0thyj merged commit 4a894f4 into master Nov 21, 2024
19 checks passed
@t1m0thyj t1m0thyj deleted the add-abort-to-search branch November 21, 2024 17:51
@t1m0thyj t1m0thyj added the release-patch Indicates a patch to existing code has been applied label Nov 21, 2024
Copy link

Release succeeded for the master branch. 🎉

The following packages have been published:

Powered by Octorelease 🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release-patch Indicates a patch to existing code has been applied released
Projects
Status: Closed
Development

Successfully merging this pull request may close these issues.

6 participants