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

Conversation

Projects
None yet
2 participants
@zaimy
Copy link

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

zaimy
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.},

This comment has been minimized.

Copy link
@zaimy

zaimy Jun 14, 2019

Author

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

This comment has been minimized.

Copy link
@hkdnet

hkdnet Jun 14, 2019

Member

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.

This comment has been minimized.

Copy link
@zaimy

zaimy Jun 15, 2019

Author

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.

@hkdnet
Copy link
Member

left a comment

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

This comment has been minimized.

Copy link
@hkdnet

hkdnet Jun 14, 2019

Member

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

This comment has been minimized.

Copy link
@zaimy

zaimy Jun 15, 2019

Author

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.},

This comment has been minimized.

Copy link
@hkdnet

hkdnet Jun 14, 2019

Member

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 added some commits Jun 15, 2019

zaimy
zaimy
@zaimy

This comment has been minimized.

Copy link
Author

commented Jun 15, 2019

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

@hkdnet

hkdnet approved these changes Jun 15, 2019

Copy link
Member

left a comment

LGTM
Thank you

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

1 check passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details
@zaimy

This comment has been minimized.

Copy link
Author

commented Jun 15, 2019

Thank you too!

@zaimy zaimy deleted the zaimy:add-options-to-listjobs-func branch Jun 15, 2019

@zaimy zaimy referenced this pull request Jun 17, 2019

Merged

Add options (API parameters). #1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.