-
Notifications
You must be signed in to change notification settings - Fork 87
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
Apply tasks changes #310
Apply tasks changes #310
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ import ( | |
"fmt" | ||
"net/http" | ||
"strconv" | ||
"strings" | ||
"time" | ||
|
||
"github.com/golang-jwt/jwt" | ||
|
@@ -51,9 +52,9 @@ type ClientInterface interface { | |
GetVersion() (resp *Version, err error) | ||
Health() (*Health, error) | ||
IsHealthy() bool | ||
GetTask(taskID int64) (resp *Task, err error) | ||
GetTasks() (resp *ResultTask, err error) | ||
WaitForTask(task *Task, options ...WaitParams) (*Task, error) | ||
GetTask(taskUID int64) (resp *Task, err error) | ||
GetTasks(param *TasksQuery) (resp *TaskResult, err error) | ||
WaitForTask(taskUID int64, options ...WaitParams) (*Task, error) | ||
GenerateTenantToken(searchRules map[string]interface{}, options *TenantTokenOptions) (resp string, err error) | ||
} | ||
|
||
|
@@ -257,10 +258,10 @@ func (c *Client) GetDumpStatus(dumpUID string) (resp *Dump, err error) { | |
return resp, nil | ||
} | ||
|
||
func (c *Client) GetTask(taskID int64) (resp *Task, err error) { | ||
func (c *Client) GetTask(taskUID int64) (resp *Task, err error) { | ||
resp = &Task{} | ||
req := internalRequest{ | ||
endpoint: "/tasks/" + strconv.FormatInt(taskID, 10), | ||
endpoint: "/tasks/" + strconv.FormatInt(taskUID, 10), | ||
method: http.MethodGet, | ||
withRequest: nil, | ||
withResponse: resp, | ||
|
@@ -273,16 +274,32 @@ func (c *Client) GetTask(taskID int64) (resp *Task, err error) { | |
return resp, nil | ||
} | ||
|
||
func (c *Client) GetTasks() (resp *ResultTask, err error) { | ||
resp = &ResultTask{} | ||
func (c *Client) GetTasks(param *TasksQuery) (resp *TaskResult, err error) { | ||
resp = &TaskResult{} | ||
req := internalRequest{ | ||
endpoint: "/tasks", | ||
method: http.MethodGet, | ||
withRequest: nil, | ||
withResponse: &resp, | ||
withQueryParams: map[string]string{}, | ||
acceptedStatusCodes: []int{http.StatusOK}, | ||
functionName: "GetTasks", | ||
} | ||
if param != nil && param.Limit != 0 { | ||
alallema marked this conversation as resolved.
Show resolved
Hide resolved
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think you should allow the user to pass There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree but for that, I should declare
And I think for this specific case when |
||
req.withQueryParams["limit"] = strconv.FormatInt(param.Limit, 10) | ||
} | ||
if param != nil && param.From != 0 { | ||
req.withQueryParams["from"] = strconv.FormatInt(param.From, 10) | ||
} | ||
if param != nil && param.Status != "" { | ||
req.withQueryParams["status"] = param.Status | ||
alallema marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
if param != nil && param.Type != "" { | ||
req.withQueryParams["type"] = param.Type | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think you can define the map inline, and after that, remove the nulls or empties like this: map[string]string{
"type": len(param.IndexUID) != 0 ? strings.Join(param.IndexUID, ",") : nil,
"limit": ...
} There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You cannot put logic inline in a struct declaration in go or I don't know how |
||
} | ||
if param != nil && len(param.IndexUID) != 0 { | ||
req.withQueryParams["indexUid"] = strings.Join(param.IndexUID, ",") | ||
} | ||
if err := c.executeRequest(req); err != nil { | ||
return nil, err | ||
} | ||
|
@@ -295,7 +312,7 @@ func (c *Client) GetTasks() (resp *ResultTask, err error) { | |
// the TaskStatus. | ||
// If no ctx and interval are provided WaitForTask will check each 50ms the | ||
// status of a task. | ||
func (c *Client) WaitForTask(task *Task, options ...WaitParams) (*Task, error) { | ||
func (c *Client) WaitForTask(taskUID int64, options ...WaitParams) (*Task, error) { | ||
if options == nil { | ||
ctx, cancelFunc := context.WithTimeout(context.Background(), time.Second*5) | ||
defer cancelFunc() | ||
|
@@ -310,7 +327,7 @@ func (c *Client) WaitForTask(task *Task, options ...WaitParams) (*Task, error) { | |
if err := options[0].Context.Err(); err != nil { | ||
return nil, err | ||
} | ||
getTask, err := c.GetTask(task.UID) | ||
getTask, err := c.GetTask(taskUID) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you know if this is the best way to handle that? I'm not sure if this will be so "intuitive" to the users.
PS: I know there are no optional args in go, so maybe they have their own way to handle that :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can use variadic parameters but I don't think it's a good way to handle it, even if it works it's made for it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, it could work but not for every case unfortunately