Skip to content

feat: add offset and limit pagination to tasks output endpoint #3057 #3058

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

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions api-docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2429,6 +2429,19 @@ paths:
- $ref: '#/parameters/project_id'
- $ref: '#/parameters/task_id'
get:
parameters:
- name: limit
in: query
required: false
type: integer
description: Maximum number of items to return. Use 0 to return all available items
x-example: 1000
- name: offset
in: query
required: false
type: integer
description: Number of items to skip before starting to collect the result set. Defaults to 0.
x-example: 0
tags:
- project
summary: Get task output
Expand Down
21 changes: 17 additions & 4 deletions api/projects/tasks.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,16 @@ package projects
import (
"bytes"
"errors"
"net/http"
"strconv"
"time"

"github.com/gorilla/context"
"github.com/semaphoreui/semaphore/api/helpers"
"github.com/semaphoreui/semaphore/db"
"github.com/semaphoreui/semaphore/services/tasks"
"github.com/semaphoreui/semaphore/util"
log "github.com/sirupsen/logrus"
"net/http"
"strconv"
"time"
)

// AddTask inserts a task into the database and returns a header or returns error
Expand Down Expand Up @@ -145,8 +146,20 @@ func GetTaskOutput(w http.ResponseWriter, r *http.Request) {
task := context.Get(r, "task").(db.Task)
project := context.Get(r, "project").(db.Project)

limitStr := r.URL.Query().Get("limit")
limit, err := strconv.Atoi(limitStr)
if err != nil {
limit = 0
}

offsetStr := r.URL.Query().Get("offset")
offset, err := strconv.Atoi(offsetStr)
if err != nil {
offset = 0
}

var output []db.TaskOutput
output, err := helpers.Store(r).GetTaskOutputs(project.ID, task.ID, db.RetrieveQueryParams{})
output, err = helpers.Store(r).GetTaskOutputs(project.ID, task.ID, db.RetrieveQueryParams{Offset: offset, Count: limit})

if err != nil {
util.LogErrorF(err, log.Fields{"error": "Bad request. Cannot get task output from database"})
Expand Down
42 changes: 12 additions & 30 deletions web/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading