Skip to content

Commit

Permalink
feat: bcs-task manager add ListTask
Browse files Browse the repository at this point in the history
  • Loading branch information
ifooth committed Sep 28, 2024
1 parent 200a2cc commit 48f6c6d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
3 changes: 3 additions & 0 deletions bcs-common/common/task/stores/iface/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ package iface

import (
"context"
"time"

"github.com/Tencent/bk-bcs/bcs-common/common/task/types"
)
Expand All @@ -29,6 +30,8 @@ type ListOption struct {
CurrentStep string
Status string
Creator string
StartGte *time.Time // StartGte start time greater or equal to
StartLte *time.Time // StartLte start time less or equal to
Sort map[string]int // Sort map for sort list results
Offset int64 // Offset offset for list results
Limit int64 // Limit limit for list results
Expand Down
15 changes: 13 additions & 2 deletions bcs-common/common/task/stores/mysql/mysql.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ func (s *mysqlStore) CreateTask(ctx context.Context, task *types.Task) error {
func (s *mysqlStore) ListTask(ctx context.Context, opt *iface.ListOption) (*iface.Pagination[types.Task], error) {
tx := s.db.WithContext(ctx)

// 0值gorm自动忽略查询
// 条件过滤 0值gorm自动忽略查询
tx = tx.Where(&TaskRecord{
TaskID: opt.TaskID,
TaskType: opt.TaskType,
Expand All @@ -117,7 +117,18 @@ func (s *mysqlStore) ListTask(ctx context.Context, opt *iface.ListOption) (*ifac
Status: opt.Status,
CurrentStep: opt.CurrentStep,
Creator: opt.Creator,
}).Order("id desc")
})

// mysql store 使用创建时间过滤
if opt.StartGte != nil {
tx = tx.Where("created_at >= ?", opt.StartGte)
}
if opt.StartLte != nil {
tx = tx.Where("created_at <= ?", opt.StartLte)
}

// 只使用id排序
tx = tx.Order("id DESC")

result, count, err := FindByPage[TaskRecord](tx, int(opt.Offset), int(opt.Limit))
if err != nil {
Expand Down

0 comments on commit 48f6c6d

Please sign in to comment.