Skip to content

Commit

Permalink
Merge pull request #9 from Azure/haitao/quote-step-name
Browse files Browse the repository at this point in the history
avoid random charactors ruins dot syntax
  • Loading branch information
haitch committed Nov 14, 2022
2 parents 73c27d5 + 90d88b0 commit 08939a9
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 21 deletions.
5 changes: 5 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,13 @@ require github.com/Azure/go-asynctask v1.3.0

require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/fogleman/gg v1.3.0 // indirect
github.com/goccy/go-graphviz v0.0.9 // indirect
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/stretchr/objx v0.5.0 // indirect
github.com/stretchr/testify v1.8.1 // indirect
golang.org/x/image v0.0.0-20200119044424-58c23975cae1 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
19 changes: 19 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,8 +1,19 @@
github.com/Azure/go-asynctask v1.3.0 h1:QBx9mGbGi4Urz4YeZ3o1c7cLGL4iUch+mGgNGupTLMI=
github.com/Azure/go-asynctask v1.3.0/go.mod h1:S1Ee5SVnt6ZUJ84brodPiHvoNfN2wgDyVO7UYTI5WeM=
github.com/corona10/goimagehash v1.0.2/go.mod h1:/l9umBhvcHQXVtQO1V6Gp1yD20STawkhRnnX0D1bvVI=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/fogleman/gg v1.3.0 h1:/7zJX8F6AaYQc57WQCyN9cAIz+4bCJGO9B+dyW29am8=
github.com/fogleman/gg v1.3.0/go.mod h1:R/bRT+9gY/C5z7JzPU0zXsXHKM4/ayA+zqcVNZzPa1k=
github.com/goccy/go-graphviz v0.0.9 h1:s/FMMJ1Joj6La3S5ApO3Jk2cwM4LpXECC2muFx3IPQQ=
github.com/goccy/go-graphviz v0.0.9/go.mod h1:wXVsXxmyMQU6TN3zGRttjNn3h+iCAS7xQFC6TlNvLhk=
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 h1:DACJavvAHhabrF08vX0COfcOBJRhZ8lUbR+ZWIs0Y5g=
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0/go.mod h1:E/TSTwGwJL78qG/PmXZO1EjYhfJinVAhrmmHX6Z8B9k=
github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI=
github.com/nfnt/resize v0.0.0-20160724205520-891127d8d1b5/go.mod h1:jpp1/29i3P1S/RLdc7JQKbRpFeM1dOBd8T9ki5s+AY8=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
Expand All @@ -13,6 +24,14 @@ github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk=
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20200204104054-c9f3fb736b72/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/image v0.0.0-20200119044424-58c23975cae1 h1:5h3ngYt7+vXCDZCup/HkCQgW5XwmSvR/nA2JmJ0RErg=
golang.org/x/image v0.0.0-20200119044424-58c23975cae1/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
Expand Down
4 changes: 2 additions & 2 deletions graph/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ var digraphTemplate = template.Must(template.New("digraph").Parse(digraphTemplat

const digraphTemplateText = `digraph {
newrank = "true"
{{ range $node := $.Nodes}} {{$node.ID}} [label="{{$node.Name}}" shape={{$node.Shape}} style={{$node.Style}} tooltip="{{$node.Tooltip}}" fillcolor={{$node.FillColor}}]
{{ range $node := $.Nodes}} "{{$node.ID}}" [label="{{$node.Name}}" shape={{$node.Shape}} style={{$node.Style}} tooltip="{{$node.Tooltip}}" fillcolor={{$node.FillColor}}]
{{ end }}
{{ range $edge := $.Edges}} {{$edge.FromNodeID}} -> {{$edge.ToNodeID}} [style={{$edge.Style}} tooltip="{{$edge.Tooltip}}" color={{$edge.Color}}]
{{ range $edge := $.Edges}} "{{$edge.FromNodeID}}" -> "{{$edge.ToNodeID}}" [style={{$edge.Style}} tooltip="{{$edge.Tooltip}}" color={{$edge.Color}}]
{{ end }}
}`
4 changes: 1 addition & 3 deletions job.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ const JobStatePending JobState = "pending"
const JobStateRunning JobState = "running"
const JobStateCompleted JobState = "completed"

const rootStepName = "$job"

type JobInterface interface {
GetStep(stepName string) (StepMeta, bool) // switch bool to error
AddStep(step StepMeta, precedingSteps ...StepMeta)
Expand Down Expand Up @@ -56,7 +54,7 @@ func NewJob(name string) *Job {
stepsDag: graph.NewGraph[*stepNode](stepConn),
}

rootStep := newStepInfo[interface{}](rootStepName, stepTypeRoot)
rootStep := newStepInfo[interface{}](name, stepTypeRoot)
rootJobFunc := func(ctx context.Context) (*interface{}, error) {
// this will pause all steps from starting, until Start() method is called.
jobStart.Wait()
Expand Down
38 changes: 22 additions & 16 deletions job_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"time"

"github.com/Azure/go-asyncjob"
"github.com/goccy/go-graphviz"
"github.com/stretchr/testify/assert"
)

Expand All @@ -23,15 +24,10 @@ func TestSimpleJob(t *testing.T) {

jb.Start(context.Background())
jobErr := jb.Wait(context.Background())
if jobErr != nil {
assert.NoError(t, jobErr)
}
assert.NoError(t, jobErr)

dotGraph, vizErr := jb.Visualize()
if vizErr != nil {
t.FailNow()
}
fmt.Println(dotGraph)
renderErr := renderGraph(jb)
assert.NoError(t, renderErr)
}

func TestSimpleJobError(t *testing.T) {
Expand All @@ -53,11 +49,8 @@ func TestSimpleJobError(t *testing.T) {
assert.Error(t, jobErr)
}

dotGraph, err := jb.Visualize()
if err != nil {
t.FailNow()
}
fmt.Println(dotGraph)
renderErr := renderGraph(jb)
assert.NoError(t, renderErr)
}

func TestSimpleJobPanic(t *testing.T) {
Expand Down Expand Up @@ -87,11 +80,24 @@ func TestSimpleJobPanic(t *testing.T) {
assert.Error(t, jobErr)
}

dotGraph, err := jb.Visualize()
renderErr := renderGraph(jb)
assert.NoError(t, renderErr)
}

func renderGraph(jb *asyncjob.Job) error {
graphStr, err := jb.Visualize()
if err != nil {
return err
}

fmt.Println(graphStr)

_, err = graphviz.ParseBytes([]byte(graphStr))
if err != nil {
t.FailNow()
return err
}
fmt.Println(dotGraph)

return nil
}

func getErrorFunc(err error, count int) func() error {
Expand Down

0 comments on commit 08939a9

Please sign in to comment.