Skip to content

Commit

Permalink
[ISSUE#653] Add Pagination Parameters to DAG List API to limit the re…
Browse files Browse the repository at this point in the history
…sponse (#664)
  • Loading branch information
halalala222 authored Aug 14, 2024
1 parent 807d3f9 commit af2a817
Show file tree
Hide file tree
Showing 30 changed files with 1,681 additions and 96 deletions.
45 changes: 43 additions & 2 deletions internal/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package client
import (
"errors"
"fmt"
"math"
"os"
"os/exec"
"path/filepath"
Expand All @@ -26,6 +27,7 @@ import (

"github.com/daguflow/dagu/internal/dag"
"github.com/daguflow/dagu/internal/dag/scheduler"
"github.com/daguflow/dagu/internal/frontend/gen/restapi/operations/dags"
"github.com/daguflow/dagu/internal/logger"
"github.com/daguflow/dagu/internal/persistence"
"github.com/daguflow/dagu/internal/persistence/model"
Expand Down Expand Up @@ -268,10 +270,10 @@ func (e *client) GetAllStatus() (
statuses []*DAGStatus, errs []string, err error,
) {
dagStore := e.dataStore.DAGStore()
dags, errs, err := dagStore.List()
dagList, errs, err := dagStore.List()

var ret []*DAGStatus
for _, d := range dags {
for _, d := range dagList {
status, err := e.readStatus(d)
if err != nil {
errs = append(errs, err.Error())
Expand All @@ -282,6 +284,41 @@ func (e *client) GetAllStatus() (
return ret, errs, err
}

func (e *client) getPageCount(total int64, limit int64) int {
pageCount := int(math.Ceil(float64(total) / float64(limit)))
if pageCount == 0 {
pageCount = 1
}

return pageCount
}

func (e *client) GetAllStatusPagination(params dags.ListDagsParams) ([]*DAGStatus, *DagListPaginationSummaryResult, error) {
var (
dagListPaginationResult *persistence.DagListPaginationResult
err error
dagStore = e.dataStore.DAGStore()
dagStatusList = make([]*DAGStatus, 0)
currentStatus *DAGStatus
)

if dagListPaginationResult, err = dagStore.ListPagination(params); err != nil {
return dagStatusList, &DagListPaginationSummaryResult{PageCount: 1}, err
}

for _, currentDag := range dagListPaginationResult.DagList {
if currentStatus, err = e.readStatus(currentDag); err != nil {
dagListPaginationResult.ErrorList = append(dagListPaginationResult.ErrorList, err.Error())
}
dagStatusList = append(dagStatusList, currentStatus)
}

return dagStatusList, &DagListPaginationSummaryResult{
PageCount: e.getPageCount(dagListPaginationResult.Count, params.Limit),
ErrorList: dagListPaginationResult.ErrorList,
}, nil
}

func (e *client) getDAG(name string) (*dag.DAG, error) {
dagStore := e.dataStore.DAGStore()
dagDetail, err := dagStore.GetDetails(name)
Expand Down Expand Up @@ -348,3 +385,7 @@ func escapeArg(input string) string {

return escaped.String()
}

func (e *client) GetTagList() ([]string, []string, error) {
return e.dataStore.DAGStore().TagList()
}
Loading

0 comments on commit af2a817

Please sign in to comment.