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

Request a list of tasks with params #41

Merged
merged 3 commits into from Feb 26, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
44 changes: 44 additions & 0 deletions worker/methods.go
Expand Up @@ -238,6 +238,50 @@ func (w *Worker) TaskList() (tasks []TaskInfo, err error) {
return out["tasks"], nil
}

type TaskListParams struct {
CodeName string
Page int
PerPage int
FromTime time.Time
ToTime time.Time
Statuses []string
}

func (w *Worker) FilteredTaskList(params TaskListParams) (tasks []TaskInfo, err error) {
out := map[string][]TaskInfo{}
url := w.tasks()

url.QueryAdd("code_name", "%s", params.CodeName)

if params.Page > 0 {
url.QueryAdd("page", "%d", params.Page)
}

if params.PerPage > 0 {
url.QueryAdd("per_page", "%d", params.PerPage)
}

if fromTimeSeconds := params.FromTime.Unix(); fromTimeSeconds > 0 {
url.QueryAdd("from_time", "%d", fromTimeSeconds)
}

if toTimeSeconds := params.ToTime.Unix(); toTimeSeconds > 0 {
url.QueryAdd("to_time", "%d", toTimeSeconds)
}

for _, status := range params.Statuses {
url.QueryAdd(status, "%d", true)
}

err = url.Req("GET", nil, &out)

if err != nil {
return
}

return out["tasks"], nil
}

// TaskQueue queues a task
func (w *Worker) TaskQueue(tasks ...Task) (taskIds []string, err error) {
outTasks := make([]map[string]interface{}, 0, len(tasks))
Expand Down