mirror of
https://github.com/hatchet-dev/hatchet.git
synced 2025-12-20 08:10:26 -06:00
* wip: api contracts * feat: implement put workflow version endpoint * add support for match existing data, get scaffolding in place for additional triggers * create additional matches * feat: durable sleep, user event matching * update protos * fix: working poc of user events, durable sleep * add migration * fix: migration column * feat: durable event listener * fix: skip overrides * fix: input -> output
40 lines
710 B
Go
40 lines
710 B
Go
package dagutils
|
|
|
|
import (
|
|
"github.com/hatchet-dev/hatchet/pkg/repository"
|
|
)
|
|
|
|
func HasCycle(steps []repository.CreateWorkflowStepOpts) bool {
|
|
graph := make(map[string][]string)
|
|
for _, step := range steps {
|
|
graph[step.ReadableId] = step.Parents
|
|
}
|
|
|
|
visited := make(map[string]bool)
|
|
var dfs func(string) bool
|
|
|
|
dfs = func(node string) bool {
|
|
if seen, ok := visited[node]; ok && seen {
|
|
return true
|
|
}
|
|
if _, ok := graph[node]; !ok {
|
|
return false
|
|
}
|
|
visited[node] = true
|
|
for _, parent := range graph[node] {
|
|
if dfs(parent) {
|
|
return true
|
|
}
|
|
}
|
|
visited[node] = false
|
|
return false
|
|
}
|
|
|
|
for _, step := range steps {
|
|
if dfs(step.ReadableId) {
|
|
return true
|
|
}
|
|
}
|
|
return false
|
|
}
|