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 options to ListJobs func. #26

Merged
merged 3 commits into from Jun 15, 2019
Merged

Add options to ListJobs func. #26

merged 3 commits into from Jun 15, 2019

Conversation

zaimy
Copy link

@zaimy zaimy commented Jun 14, 2019

Hi,

I had Treasure Data support taught us that the parameters from, to and status can be specified with the end point of Treasure Data API /v3/job/list (*).

By merging this pull request, it becomes possible to specify the parameters as shown below.

func main() {
  client, _ := td_client.NewTDClient(td_client.Settings {
    ApiKey: <APIKEY>,
  })
  // use parametors
  options := &td_client.ListJobsOptions{}
  client.ListJobsWithOptions(options.WithFrom(0).WithTo(9).WithStatus("running"))
  // default
  client.ListJobs()
}

I made a new function ListJobsWithOptions in consideration of the backward compatibility of ListJobs, but I think that there is also an option that ListJobs takes arguments in strictness.
I would like to hear the thoughts of the contributors.

(*) Documents contains several parameters, including the old ones, but I understand that the currently available parameters are from, to, status and slower_than. The last one is written in the document to be avoided, so the implementation added in this pull request is not support this.
https://support.treasuredata.com/hc/en-us/articles/360001260527-REST-API#get-v3joblist
https://support.treasuredata.com/hc/en-us/articles/360020228934-Treasure-Data-Job-APIs

api_job.go Outdated
@@ -82,8 +82,8 @@ var listJobsSchema = map[string]interface{}{
},
},
"count": Optional{0, 0},
"to": Optional{"", "?"},
"from": Optional{"", "?"},
"to": Optional{0., 0.},
Copy link
Author

Choose a reason for hiding this comment

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

Currently the API server is returning a float instead of a string.

Copy link
Member

Choose a reason for hiding this comment

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

That's right. The API server does not return a string.
But why don't you use int? Both From and To are offset numbers, so they are always int.

Copy link
Author

Choose a reason for hiding this comment

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

During development, Go's error message showed me that it was a float, and I followed it.
As you say, int is satisfactory. I fixed it on d4c3b14.

Copy link
Member

@hkdnet hkdnet left a comment

Choose a reason for hiding this comment

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

Thank you for your PR.
This is almost fine but I wrote some comments.

api_job.go Outdated

func (options *ListJobsOptions) WithStatus(status string) *ListJobsOptions {
if status == "running" || status == "queued" || status == "success" || status == "error" {
options.status = status
Copy link
Member

Choose a reason for hiding this comment

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

This line contains leading spaces. Please use onnly tabs for indent.

Copy link
Author

Choose a reason for hiding this comment

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

Sorry. I fixed it.

api_job.go Outdated
@@ -82,8 +82,8 @@ var listJobsSchema = map[string]interface{}{
},
},
"count": Optional{0, 0},
"to": Optional{"", "?"},
"from": Optional{"", "?"},
"to": Optional{0., 0.},
Copy link
Member

Choose a reason for hiding this comment

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

That's right. The API server does not return a string.
But why don't you use int? Both From and To are offset numbers, so they are always int.

@zaimy
Copy link
Author

zaimy commented Jun 15, 2019

Thank you for your comments! I added some commits.
Would you check those?

Copy link
Member

@hkdnet hkdnet left a comment

Choose a reason for hiding this comment

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

LGTM
Thank you

@hkdnet hkdnet merged commit 172f27e into treasure-data:master Jun 15, 2019
@zaimy
Copy link
Author

zaimy commented Jun 15, 2019

Thank you too!

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.

None yet

2 participants