lang: funcs: dage: Add a Graph method to improve the API
This also adds it to the GraphAPI so that users of it can pull out a graph when needed. It's not likely to be used by the dage engine consumers.
This commit is contained in:
@@ -504,6 +504,14 @@ func (obj *Engine) FindEdge(f1, f2 interfaces.Func) *interfaces.FuncEdge {
|
||||
return fe
|
||||
}
|
||||
|
||||
// Graph returns a copy of the contained graph.
|
||||
func (obj *Engine) Graph() *pgraph.Graph {
|
||||
//obj.graphMutex.Lock() // XXX: should this be a RLock?
|
||||
//defer obj.graphMutex.Unlock() // XXX: should this be an RUnlock?
|
||||
|
||||
return obj.graph.Copy()
|
||||
}
|
||||
|
||||
// Lock must be used before modifying the running graph. Make sure to Unlock
|
||||
// when done.
|
||||
// XXX: should Lock take a context if we want to bail mid-way?
|
||||
|
||||
@@ -510,7 +510,7 @@ func (obj *graphTxn) commit() error {
|
||||
//gv := &pgraph.Graphviz{
|
||||
// Filename: fmt.Sprintf("/tmp/txn-graphviz-%d.dot", d),
|
||||
// Graphs: map[*pgraph.Graph]*pgraph.GraphvizOpts{
|
||||
// engine.graph: nil,
|
||||
// obj.Graph(): nil,
|
||||
// },
|
||||
//}
|
||||
//if err := gv.Exec(); err != nil {
|
||||
|
||||
@@ -115,6 +115,10 @@ func (obj *testGraphAPI) FindEdge(f1, f2 interfaces.Func) *interfaces.FuncEdge {
|
||||
return fe
|
||||
}
|
||||
|
||||
func (obj *testGraphAPI) Graph() *pgraph.Graph {
|
||||
return obj.graph.Copy()
|
||||
}
|
||||
|
||||
type testNullFunc struct {
|
||||
name string
|
||||
}
|
||||
|
||||
@@ -262,6 +262,9 @@ type GraphAPI interface {
|
||||
HasVertex(Func) bool
|
||||
FindEdge(Func, Func) *FuncEdge
|
||||
LookupEdge(*FuncEdge) (Func, Func, bool)
|
||||
|
||||
// Graph returns a copy of the current graph.
|
||||
Graph() *pgraph.Graph
|
||||
}
|
||||
|
||||
// Txn is the interface that the engine graph API makes available so that
|
||||
|
||||
Reference in New Issue
Block a user