Skip to content

Commit

Permalink
Merge pull request #271 from yohamta/fix-history-issue
Browse files Browse the repository at this point in the history
admin-web: fix execution history sorting issue
  • Loading branch information
yottahmd authored Aug 16, 2022
2 parents bb682fa + 581c5a2 commit ddb8aa7
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 12 deletions.
4 changes: 2 additions & 2 deletions admin/src/components/organizations/ExecutionHistory.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Box } from '@mui/material';
import React, { useEffect } from 'react';
import React from 'react';
import { GridData, LogData } from '../../models/api';
import { DAGContext } from '../../contexts/DAGContext';
import { Handlers, StatusFile } from '../../models';
Expand Down Expand Up @@ -32,7 +32,7 @@ type HistoryTableProps = {
function DAGHistoryTable({ GridData, Logs }: HistoryTableProps) {
const [idx, setIdx] = React.useState(Logs.length - 1);
const logs = React.useMemo(() => {
return Logs.reverse();
return Logs;
}, [Logs]);

const handlers = logs.length > idx ? Handlers(logs[idx].Status) : null;
Expand Down
4 changes: 2 additions & 2 deletions admin/src/pages/dags/dag/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import DAGSpecErrors from '../../../components/molecules/DAGSpecErrors';
import DAGStatus from '../../../components/organizations/DAGStatus';
import { DAGContext } from '../../../contexts/DAGContext';
import DAGSpec from '../../../components/organizations/DAGSpec';
import DAGHistory from '../../../components/organizations/ExecutionHistory';
import ExecutionHistory from '../../../components/organizations/ExecutionHistory';
import ExecutionLog from '../../../components/organizations/ExecutionLog';
import { Box, Stack, Tab, Tabs } from '@mui/material';
import Title from '../../../components/atoms/Title';
Expand Down Expand Up @@ -124,7 +124,7 @@ function DAGDetails() {
<Route
path={'/history'}
element={
<DAGHistory logData={data.LogData} isLoading={isValidating} />
<ExecutionHistory logData={data.LogData} isLoading={isValidating} />
}
/>
<Route
Expand Down
4 changes: 4 additions & 0 deletions examples/example.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ steps:
command: "sleep 2"
depends:
- Reconcile
- name: "ttt"
command: "sleep 2"
depends:
- Cleaning
handlerOn:
exit:
command: echo finished
3 changes: 3 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,16 @@ require (
gopkg.in/yaml.v2 v2.4.0
)

require golang.org/x/exp v0.0.0-20220303212507-bbda1eaf7a17 // indirect

require (
github.com/cpuguy83/go-md2man/v2 v2.0.1 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/mattn/go-runewidth v0.0.13 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/rivo/uniseg v0.3.4 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/samber/lo v1.27.0
golang.org/x/net v0.0.0-20220812174116-3211cb980234 // indirect
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
Expand Down
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ github.com/robfig/cron/v3 v3.0.1 h1:WdRxkvbJztn8LMz/QEvLN5sBU+xKpSqwwUO1Pjr4qDs=
github.com/robfig/cron/v3 v3.0.1/go.mod h1:eQICP3HwyT7UooqI/z+Ov+PtYAWygg1TEWWzGIFLtro=
github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk=
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/samber/lo v1.27.0 h1:GOyDWxsblvqYobqsmUuMddPa2/mMzkKyojlXol4+LaQ=
github.com/samber/lo v1.27.0/go.mod h1:it33p9UtPMS7z72fP4gw/EIfQB2eI8ke7GR2wc6+Rhg=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
Expand All @@ -36,6 +38,8 @@ github.com/stretchr/testify v1.8.0 h1:pSgiaMZlXftHpm5L7V1+rVB+AZJydKsMxsQBIJw4PK
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/urfave/cli/v2 v2.4.5 h1:AWCiaqBc+38MxX6nJfjRQyyd2Gq50sOan+AEyv/vFhM=
github.com/urfave/cli/v2 v2.4.5/go.mod h1:oDzoM7pVwz6wHn5ogWgFUU1s4VJayeQS+aEZDqXIEJs=
golang.org/x/exp v0.0.0-20220303212507-bbda1eaf7a17 h1:3MTrJm4PyNL9NBqvYDSj3DHl46qQakyfqfWo4jgfaEM=
golang.org/x/exp v0.0.0-20220303212507-bbda1eaf7a17/go.mod h1:lgLbSvA5ygNOMpwM/9anMpWVlVJ7Z+cHWq/eFuinpGE=
golang.org/x/net v0.0.0-20211029224645-99673261e6eb/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/net v0.0.0-20220812174116-3211cb980234 h1:RDqmgfe7SvlMWoqC3xwQ2blLO3fcWcxMa3eBLRdRW7E=
golang.org/x/net v0.0.0-20220812174116-3211cb980234/go.mod h1:YDH+HFinaLZZlnHAfSS6ZXJJ9M9t4Dl22yv3iI2vPwk=
Expand Down
20 changes: 12 additions & 8 deletions internal/admin/handlers/dag.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"sort"
"strings"

"github.com/samber/lo"
"github.com/yohamta/dagu/internal/constants"
"github.com/yohamta/dagu/internal/controller"
"github.com/yohamta/dagu/internal/dag"
Expand Down Expand Up @@ -417,10 +418,6 @@ func readFile(f string, decorder *encoding.Decoder) ([]byte, error) {
}

func buildLog(logs []*models.StatusFile) *Log {
ret := &Log{
GridData: []*dagStatus{},
Logs: logs,
}
tmp := map[string][]scheduler.NodeStatus{}
add := func(step *models.Node, i int) {
n := step.Name
Expand All @@ -434,11 +431,12 @@ func buildLog(logs []*models.StatusFile) *Log {
add(s, i)
}
}
grid := []*dagStatus{}
for k, v := range tmp {
ret.GridData = append(ret.GridData, &dagStatus{Name: k, Vals: v})
grid = append(grid, &dagStatus{Name: k, Vals: v})
}
sort.Slice(ret.GridData, func(i, c int) bool {
return strings.Compare(ret.GridData[i].Name, ret.GridData[c].Name) <= 0
sort.Slice(grid, func(i, c int) bool {
return strings.Compare(grid[i].Name, grid[c].Name) <= 0
})
tmp = map[string][]scheduler.NodeStatus{}
for i, l := range logs {
Expand All @@ -457,9 +455,15 @@ func buildLog(logs []*models.StatusFile) *Log {
}
for _, h := range []string{constants.OnSuccess, constants.OnFailure, constants.OnCancel, constants.OnExit} {
if v, ok := tmp[h]; ok {
ret.GridData = append(ret.GridData, &dagStatus{Name: h, Vals: v})
grid = append(grid, &dagStatus{Name: h, Vals: v})
}
}

ret := &Log{
Logs: lo.Reverse(logs),
GridData: grid,
}

return ret
}

Expand Down

0 comments on commit ddb8aa7

Please sign in to comment.