Skip to content

Commit

Permalink
move DAG status struct
Browse files Browse the repository at this point in the history
  • Loading branch information
yohamta committed Sep 10, 2023
1 parent e9d9d72 commit a1735fb
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 26 deletions.
25 changes: 7 additions & 18 deletions internal/engine/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ type Engine interface {
UpdateStatus(dag *dag.DAG, status *model.Status) error
UpdateDAGSpec(d *dag.DAG, spec string) error
DeleteDAG(dag *dag.DAG) error
ReadAllStatus(DAGsDir string) (statuses []*DAGStatus, errs []string, err error)
ReadStatus(dagLocation string, loadMetadataOnly bool) (*DAGStatus, error)
ReadAllStatus(DAGsDir string) (statuses []*persistence.DAGStatus, errs []string, err error)
ReadStatus(dagLocation string, loadMetadataOnly bool) (*persistence.DAGStatus, error)
}

type engineImpl struct {
Expand All @@ -44,17 +44,6 @@ type engineImpl struct {
workDir string
}

// TODO: this should not be here.
type DAGStatus struct {
File string
Dir string
DAG *dag.DAG
Status *model.Status
Suspended bool
Error error
ErrorT *string
}

var (
_DAGTemplate = []byte(`steps:
- name: step1
Expand Down Expand Up @@ -259,8 +248,8 @@ func (e *engineImpl) DeleteDAG(dag *dag.DAG) error {
}

// ReadAllStatus reads all DAGStatus
func (e *engineImpl) ReadAllStatus(DAGsDir string) (statuses []*DAGStatus, errs []string, err error) {
statuses = []*DAGStatus{}
func (e *engineImpl) ReadAllStatus(DAGsDir string) (statuses []*persistence.DAGStatus, errs []string, err error) {
statuses = []*persistence.DAGStatus{}
errs = []string{}
if !utils.FileExists(DAGsDir) {
if err = os.MkdirAll(DAGsDir, 0755); err != nil {
Expand All @@ -285,7 +274,7 @@ func (e *engineImpl) ReadAllStatus(DAGsDir string) (statuses []*DAGStatus, errs
}

// ReadStatus loads DAG from config file.
func (e *engineImpl) ReadStatus(dagLocation string, loadMetadataOnly bool) (*DAGStatus, error) {
func (e *engineImpl) ReadStatus(dagLocation string, loadMetadataOnly bool) (*persistence.DAGStatus, error) {
var (
cl = dag.Loader{}
d *dag.DAG
Expand Down Expand Up @@ -317,8 +306,8 @@ func (e *engineImpl) ReadStatus(dagLocation string, loadMetadataOnly bool) (*DAG
return e.newDAGStatus(d, status, err), err
}

func (e *engineImpl) newDAGStatus(d *dag.DAG, s *model.Status, err error) *DAGStatus {
ret := &DAGStatus{
func (e *engineImpl) newDAGStatus(d *dag.DAG, s *model.Status, err error) *persistence.DAGStatus {
ret := &persistence.DAGStatus{
File: filepath.Base(d.Location),
Dir: filepath.Dir(d.Location),
DAG: d,
Expand Down
10 changes: 10 additions & 0 deletions internal/persistence/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,14 @@ type (
DAG *dag.DAG
Matches []*grep.Match
}

DAGStatus struct {
File string
Dir string
DAG *dag.DAG
Status *model.Status
Suspended bool
Error error
ErrorT *string
}
)
3 changes: 2 additions & 1 deletion service/frontend/handlers/dag.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/dagu-dev/dagu/internal/constants"
"github.com/dagu-dev/dagu/internal/dag"
"github.com/dagu-dev/dagu/internal/engine"
"github.com/dagu-dev/dagu/internal/persistence"
"github.com/dagu-dev/dagu/internal/persistence/jsondb"
domain "github.com/dagu-dev/dagu/internal/persistence/model"
"github.com/dagu-dev/dagu/internal/scheduler"
Expand Down Expand Up @@ -150,7 +151,7 @@ func (h *DAGHandler) GetList(_ operations.ListDagsParams) (*models.ListDagsRespo
}

// TODO: remove this if it's not needed
_, _, hasErr := lo.FindIndexOf(dags, func(d *engine.DAGStatus) bool {
_, _, hasErr := lo.FindIndexOf(dags, func(d *persistence.DAGStatus) bool {
return d.Error != nil
})

Expand Down
6 changes: 3 additions & 3 deletions service/frontend/handlers/response/dag_detail.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ package response

import (
"github.com/dagu-dev/dagu/internal/dag"
"github.com/dagu-dev/dagu/internal/engine"
"github.com/dagu-dev/dagu/internal/persistence"
domain "github.com/dagu-dev/dagu/internal/persistence/model"
"github.com/dagu-dev/dagu/service/frontend/models"
"github.com/samber/lo"
)

func ToGetDagDetailResponse(
workflowStatus *engine.DAGStatus,
workflowStatus *persistence.DAGStatus,
tab string,
) *models.GetDagDetailsResponse {
return &models.GetDagDetailsResponse{
Expand All @@ -22,7 +22,7 @@ func ToGetDagDetailResponse(
}
}

func ToDagStatusWithDetails(dagStatus *engine.DAGStatus) *models.DagStatusWithDetails {
func ToDagStatusWithDetails(dagStatus *persistence.DAGStatus) *models.DagStatusWithDetails {
return &models.DagStatusWithDetails{
DAG: ToDagDetail(dagStatus.DAG),
Dir: lo.ToPtr(dagStatus.Dir),
Expand Down
8 changes: 4 additions & 4 deletions service/frontend/handlers/response/dag_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,26 @@ package response

import (
"github.com/dagu-dev/dagu/internal/dag"
"github.com/dagu-dev/dagu/internal/engine"
"github.com/dagu-dev/dagu/internal/persistence"
"github.com/dagu-dev/dagu/service/frontend/models"
"github.com/samber/lo"
)

func ToListDagResponse(
dagStatusList []*engine.DAGStatus,
dagStatusList []*persistence.DAGStatus,
errs []string,
hasError bool,
) *models.ListDagsResponse {
return &models.ListDagsResponse{
DAGs: lo.Map(dagStatusList, func(item *engine.DAGStatus, _ int) *models.DagListItem {
DAGs: lo.Map(dagStatusList, func(item *persistence.DAGStatus, _ int) *models.DagListItem {
return ToDagListItem(item)
}),
Errors: errs,
HasError: lo.ToPtr(hasError),
}
}

func ToDagListItem(s *engine.DAGStatus) *models.DagListItem {
func ToDagListItem(s *persistence.DAGStatus) *models.DagListItem {
return &models.DagListItem{
Dir: lo.ToPtr(s.Dir),
Error: lo.ToPtr(toErrorText(s.Error)),
Expand Down

0 comments on commit a1735fb

Please sign in to comment.