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

feat(javascript): add waitForTask in search client #510

Merged
merged 14 commits into from
May 19, 2022
Merged

Conversation

eunjae-lee
Copy link
Contributor

@eunjae-lee eunjae-lee commented May 18, 2022

🧭 What and Why

🎟 JIRA Ticket: https://algolia.atlassian.net/browse/APIC-472

Changes included:

  • Add waitForTask method in the JS search client
  • Add createRetryablePromise method in the client-common package.

We can use createRetryablePromise for other types of wait methods if we need any. Also, users can use it to create their own waitForTask with custom configuration.

🧪 Test

  • CI

@netlify
Copy link

netlify bot commented May 18, 2022

Deploy Preview for api-clients-automation ready!

Name Link
🔨 Latest commit fbdb035
🔍 Latest deploy log https://app.netlify.com/sites/api-clients-automation/deploys/62865694359e4c0008837aef
😎 Deploy Preview https://deploy-preview-510--api-clients-automation.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

@algolia-bot
Copy link
Collaborator

algolia-bot commented May 18, 2022

✗ The generated branch has been deleted.

If the PR has been merged, you can check the generated code on the main branch.
You can still access the code generated on main via this commit.

@eunjae-lee eunjae-lee marked this pull request as ready for review May 18, 2022 15:46
@eunjae-lee eunjae-lee requested review from a team, damcou and shortcuts and removed request for a team May 18, 2022 15:49
Copy link
Member

@shortcuts shortcuts left a comment

Choose a reason for hiding this comment

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

that's nice!!!!!!!!!! few comments :D

templates/javascript/api-single.mustache Outdated Show resolved Hide resolved
templates/javascript/api-single.mustache Show resolved Hide resolved
Comment on lines 6 to 11
}: {
func: () => Promise<TResponse>;
validate: (response: TResponse) => boolean;
maxTrial?: number;
timeout?: (retryCount: number) => number;
}): Promise<TResponse> {
Copy link
Member

Choose a reason for hiding this comment

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

We can provide a type and export it, with its documentation

@@ -0,0 +1,36 @@
export function createRetryablePromise<TResponse>({
Copy link
Member

Choose a reason for hiding this comment

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

Can we provide some docs here pls?

if (isValid) {
resolve(response);
} else if (retryCount + 1 >= maxTrial) {
reject(new Error('The maximum number of trials exceeded.'));
Copy link
Member

Choose a reason for hiding this comment

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

We can provide the context in the error (nb retries etc.) just to give confidence it fully executed

Copy link
Collaborator

@millotp millotp left a comment

Choose a reason for hiding this comment

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

very nice api !

@eunjae-lee eunjae-lee requested review from millotp and shortcuts May 19, 2022 09:58
Copy link
Member

@shortcuts shortcuts left a comment

Choose a reason for hiding this comment

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

Looks clean!

}: {
indexName: string;
taskID: number;
} & Omit<CreateRetryablePromiseOptions, 'func' | 'validate'>): Promise<GetTaskResponse> {
Copy link
Collaborator

@millotp millotp May 19, 2022

Choose a reason for hiding this comment

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

This function should returnPromise<void>, we already know that it will return status: 'published' right ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah I just realized GetTaskResponse only includes status. In the scope of waitForTask, we can ignore the return value from createRetryablePromise.

Copy link
Member

@shortcuts shortcuts left a comment

Choose a reason for hiding this comment

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

LGTM :D

* @param waitForTaskProps.indexName - The index in which to perform the request.
* @param waitForTaskProps.taskID - The unique identifier of the task to wait for.
*/
waitForTask({
Copy link
Member

Choose a reason for hiding this comment

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

Should we add a task to the backlog to write tests for those methods?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not sure if we need a test for waitForTask since it's a combination of getTask and createRetryablePromise and both of the methods have their own tests. We could, in the future, have integration tests with real APIs. WDYT?

@eunjae-lee eunjae-lee enabled auto-merge (squash) May 19, 2022 14:45
@eunjae-lee eunjae-lee merged commit 4f8d355 into main May 19, 2022
@eunjae-lee eunjae-lee deleted the feat/wait-task branch May 19, 2022 14:50
This was referenced May 19, 2022
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.

4 participants