diff --git a/internal/engine/engine.go b/internal/engine/engine.go index cba0ac0a..d9fcfde8 100644 --- a/internal/engine/engine.go +++ b/internal/engine/engine.go @@ -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 { @@ -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 @@ -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 { @@ -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 @@ -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, diff --git a/internal/persistence/interface.go b/internal/persistence/interface.go index 5ff0482d..a9b656c5 100644 --- a/internal/persistence/interface.go +++ b/internal/persistence/interface.go @@ -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 + } ) diff --git a/service/frontend/handlers/dag.go b/service/frontend/handlers/dag.go index 09dbe1fb..5d04401d 100644 --- a/service/frontend/handlers/dag.go +++ b/service/frontend/handlers/dag.go @@ -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" @@ -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 }) diff --git a/service/frontend/handlers/response/dag_detail.go b/service/frontend/handlers/response/dag_detail.go index 7ba80ddd..e01e04d1 100644 --- a/service/frontend/handlers/response/dag_detail.go +++ b/service/frontend/handlers/response/dag_detail.go @@ -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{ @@ -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), diff --git a/service/frontend/handlers/response/dag_list.go b/service/frontend/handlers/response/dag_list.go index 7a153f61..6c8aa40e 100644 --- a/service/frontend/handlers/response/dag_list.go +++ b/service/frontend/handlers/response/dag_list.go @@ -2,18 +2,18 @@ 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, @@ -21,7 +21,7 @@ func ToListDagResponse( } } -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)),