From 37fc63aacca4da682feae67d0a098bfe2ddd72cf Mon Sep 17 00:00:00 2001 From: Wenkai Yin Date: Wed, 6 Jul 2016 14:12:16 +0800 Subject: [PATCH] add parameter 'num' to list jobs --- api/replication_job.go | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/api/replication_job.go b/api/replication_job.go index 7ced0bcac..93ce92183 100644 --- a/api/replication_job.go +++ b/api/replication_job.go @@ -61,6 +61,7 @@ func (ra *RepJobAPI) List() { var policyID int64 var repository, status string var startTime, endTime *time.Time + var num int var err error policyIDStr := ra.GetString("policy_id") @@ -71,6 +72,17 @@ func (ra *RepJobAPI) List() { } } + numStr := ra.GetString("num") + if len(numStr) != 0 { + num, err = strconv.Atoi(numStr) + if err != nil { + ra.CustomAbort(http.StatusBadRequest, fmt.Sprintf("invalid num: %s", numStr)) + } + } + if num <= 0 { + num = 200 + } + endTimeStr := ra.GetString("end_time") if len(endTimeStr) != 0 { i, err := strconv.ParseInt(endTimeStr, 10, 64) @@ -100,7 +112,7 @@ func (ra *RepJobAPI) List() { repository = ra.GetString("repository") status = ra.GetString("status") - jobs, err := dao.FilterRepJobs(policyID, repository, status, startTime, endTime, 1000) + jobs, err := dao.FilterRepJobs(policyID, repository, status, startTime, endTime, num) if err != nil { log.Errorf("failed to filter jobs according policy ID %d, repository %s, status %s: %v", policyID, repository, status, err) ra.RenderError(http.StatusInternalServerError, "Failed to query job")