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

Redesign update API to task API #262

Merged
merged 4 commits into from
Feb 1, 2022
Merged

Conversation

alallema
Copy link
Contributor

Breaking Changes

All the actions on indexes are now asynchronous:

  • CreateIndex(), UpdateIndex(), DeleteIndex() return a Task response instead of an Index.
  • index.Create and index.Delete from index return a task.
  • WaitForPendingUpdate()
    • is renamed into WaitForTask
    • the current index.WaitForTask() method call /tasks/:uid
  • index.GetUpdateStatus is renamed index.GetTask
  • index.GetAllUpdateStatus is renamed index.GetTasks

Notes: The only two methods that now return an Index are client.Index() and client.GetIndex()

Enhancements

  • new method client.WaitForTask() call /tasks/:uid
  • new method client.WaitForTask()
  • new method client.GetTasks that calls /tasks
  • new method client.GetTask that calls /tasks/:uid

@alallema alallema added the breaking-change The related changes are breaking for the users label Jan 27, 2022
@alallema alallema force-pushed the redesign-api branch 2 times, most recently from fcdcc9b to 7f764bf Compare January 27, 2022 17:44
client.go Outdated
GetTask(taskID int64) (resp *Task, err error)
GetTasks() (resp *ResultTask, err error)
WaitForTask(ctx context.Context, interval time.Duration, taskID *Task) (*Task, error)
DefaultWaitForTask(taskID *Task) (*Task, error)
Copy link
Contributor

Choose a reason for hiding this comment

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

What is defaultWaitForTask ?

I see that it is when you provide the default values. Is this the naming convention in GO ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is the WaitForTask with default values. I don't think this naming is a specific convention in go. I can rename it if you have a better naming 🤩

Copy link
Contributor

Choose a reason for hiding this comment

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

in waitForTask you can add a structure the following way

type waitParams struct{
   interval: int,
   taskId: int
}

provide this as a parameter and in case of null use the default value?

function waitForTask(taskId: int, params WaitParams) {
   var interval = 500 // default value
   if (params.interval != 0) {
     interval = params.interval
  }
  // etc ...
}

would something like that be possible?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, but you had to specify the last param at nil like:

	client. waitForTask(0, nil)

There is no optional parameters in golang but I can use variadic args and do something like:

func (c *Client) WaitForTask(task *Task, options ...waitParams) (*Task, error) {
	if (options == nil) {
		ctx, cancelFunc := context.WithTimeout(context.Background(), time.Second*5)
		defer cancelFunc()
		options[0].Context = ctx
		options[0].Interval = time.Millisecond*50
	}
... do waitForTask ...
}

And I can use it like:

	client. waitForTask(0)
	// OR
	client. waitForTask(0, &waitParams{ctx, time.Millisecond*10})

I'm not sure which one is the most elegant because in the second option I get the waitParams as an array.
What do you think?

client_request.go Show resolved Hide resolved
client.go Outdated Show resolved Hide resolved
alallema and others added 2 commits January 31, 2022 13:18
Co-authored-by: cvermand <33010418+bidoubiwa@users.noreply.github.com>
@bidoubiwa
Copy link
Contributor

I like the variadic args! I'm not so used to goland so I hope it is something that is not choking to the user

Copy link
Contributor

@bidoubiwa bidoubiwa left a comment

Choose a reason for hiding this comment

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

LGTM 🔥

@alallema
Copy link
Contributor Author

alallema commented Feb 1, 2022

I like the variadic args! I'm not so used to goland so I hope it is something that is not choking to the user

Me too!

@alallema
Copy link
Contributor Author

alallema commented Feb 1, 2022

bors merge

@bors
Copy link
Contributor

bors bot commented Feb 1, 2022

@bors bors bot merged commit af85199 into bump-meilisearch-v0.25.0 Feb 1, 2022
@bors bors bot deleted the redesign-api branch February 1, 2022 12:56
bors bot added a commit that referenced this pull request Feb 8, 2022
247: Changes related to the next MeiliSearch release (v0.25.0) r=alallema a=meili-bot

Related to this issue: meilisearch/integration-guides#157

This PR:
- gathers the changes related to the next MeiliSearch release (v0.25.0) so that this package is ready when the official release is out.
- should pass the tests against the [latest pre-release of MeiliSearch](https://github.com/meilisearch/MeiliSearch/releases).
- might eventually contain test failures until the MeiliSearch v0.25.0 is out.

⚠️ This PR should NOT be merged until the next release of MeiliSearch (v0.25.0) is out.

_This PR is auto-generated for the [pre-release week](https://github.com/meilisearch/integration-guides/blob/master/guides/pre-release-week.md) purpose._

Done:
- #254 
- #255 
- #256 
- #257
- #262 
- #264
- #265 
- #266 

Co-authored-by: meili-bot <74670311+meili-bot@users.noreply.github.com>
Co-authored-by: Amélie <alallema@users.noreply.github.com>
Co-authored-by: alallema <amelie@meilisearch.com>
Co-authored-by: bors[bot] <26634292+bors[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking-change The related changes are breaking for the users
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants