Skip to content

Commit 0345f62

Browse files
authored
Merge pull request #395 from meilisearch/add_cancel_task_api_for_v0.30.0
Add cancel task api for v0.30.0
2 parents 9189a95 + a55baa0 commit 0345f62

File tree

4 files changed

+1917
-562
lines changed

4 files changed

+1917
-562
lines changed

client.go

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@ type ClientInterface interface {
5454
IsHealthy() bool
5555
GetTask(taskUID int64) (resp *Task, err error)
5656
GetTasks(param *TasksQuery) (resp *TaskResult, err error)
57+
CancelTasks(param *CancelTasksQuery) (resp *TaskInfo, err error)
58+
DeleteTasks(param *DeleteTasksQuery) (resp *TaskInfo, err error)
59+
SwapIndexes(param []SwapIndexesParams) (resp *TaskInfo, err error)
5760
WaitForTask(taskUID int64, options ...WaitParams) (*Task, error)
5861
GenerateTenantToken(APIKeyUID string, searchRules map[string]interface{}, options *TenantTokenOptions) (resp string, err error)
5962
}
@@ -285,6 +288,86 @@ func (c *Client) GetTasks(param *TasksQuery) (resp *TaskResult, err error) {
285288
return resp, nil
286289
}
287290

291+
func (c *Client) CancelTasks(param *CancelTasksQuery) (resp *TaskInfo, err error) {
292+
resp = &TaskInfo{}
293+
req := internalRequest{
294+
endpoint: "/tasks/cancel",
295+
method: http.MethodPost,
296+
withRequest: nil,
297+
withResponse: &resp,
298+
withQueryParams: map[string]string{},
299+
acceptedStatusCodes: []int{http.StatusOK},
300+
functionName: "CancelTasks",
301+
}
302+
if param != nil {
303+
paramToSend := &TasksQuery{
304+
UIDS: param.UIDS,
305+
IndexUIDS: param.IndexUIDS,
306+
Statuses: param.Statuses,
307+
Types: param.Types,
308+
BeforeEnqueuedAt: param.BeforeEnqueuedAt,
309+
AfterEnqueuedAt: param.AfterEnqueuedAt,
310+
BeforeStartedAt: param.BeforeStartedAt,
311+
AfterStartedAt: param.AfterStartedAt,
312+
}
313+
encodeTasksQuery(paramToSend, &req)
314+
}
315+
if err := c.executeRequest(req); err != nil {
316+
return nil, err
317+
}
318+
return resp, nil
319+
}
320+
321+
func (c *Client) DeleteTasks(param *DeleteTasksQuery) (resp *TaskInfo, err error) {
322+
resp = &TaskInfo{}
323+
req := internalRequest{
324+
endpoint: "/tasks",
325+
method: http.MethodDelete,
326+
withRequest: nil,
327+
withResponse: &resp,
328+
withQueryParams: map[string]string{},
329+
acceptedStatusCodes: []int{http.StatusOK},
330+
functionName: "DeleteTasks",
331+
}
332+
if param != nil {
333+
paramToSend := &TasksQuery{
334+
UIDS: param.UIDS,
335+
IndexUIDS: param.IndexUIDS,
336+
Statuses: param.Statuses,
337+
Types: param.Types,
338+
CanceledBy: param.CanceledBy,
339+
BeforeEnqueuedAt: param.BeforeEnqueuedAt,
340+
AfterEnqueuedAt: param.AfterEnqueuedAt,
341+
BeforeStartedAt: param.BeforeStartedAt,
342+
AfterStartedAt: param.AfterStartedAt,
343+
BeforeFinishedAt: param.BeforeFinishedAt,
344+
AfterFinishedAt: param.AfterFinishedAt,
345+
}
346+
encodeTasksQuery(paramToSend, &req)
347+
}
348+
if err := c.executeRequest(req); err != nil {
349+
return nil, err
350+
}
351+
return resp, nil
352+
}
353+
354+
func (c *Client) SwapIndexes(param []SwapIndexesParams) (resp *TaskInfo, err error) {
355+
resp = &TaskInfo{}
356+
req := internalRequest{
357+
endpoint: "/swap-indexes",
358+
method: http.MethodPost,
359+
contentType: contentTypeJSON,
360+
withRequest: param,
361+
withResponse: &resp,
362+
acceptedStatusCodes: []int{http.StatusAccepted},
363+
functionName: "SwapIndexes",
364+
}
365+
if err := c.executeRequest(req); err != nil {
366+
return nil, err
367+
}
368+
return resp, nil
369+
}
370+
288371
// WaitForTask waits for a task to be processed
289372
//
290373
// The function will check by regular interval provided in parameter interval

0 commit comments

Comments
 (0)