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:
James Shubin
2024-01-22 13:57:34 -05:00
parent dd20bd5486
commit 20c8a856a2
4 changed files with 16 additions and 1 deletions

View File

@@ -504,6 +504,14 @@ func (obj *Engine) FindEdge(f1, f2 interfaces.Func) *interfaces.FuncEdge {
return fe 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 // Lock must be used before modifying the running graph. Make sure to Unlock
// when done. // when done.
// XXX: should Lock take a context if we want to bail mid-way? // XXX: should Lock take a context if we want to bail mid-way?

View File

@@ -510,7 +510,7 @@ func (obj *graphTxn) commit() error {
//gv := &pgraph.Graphviz{ //gv := &pgraph.Graphviz{
// Filename: fmt.Sprintf("/tmp/txn-graphviz-%d.dot", d), // Filename: fmt.Sprintf("/tmp/txn-graphviz-%d.dot", d),
// Graphs: map[*pgraph.Graph]*pgraph.GraphvizOpts{ // Graphs: map[*pgraph.Graph]*pgraph.GraphvizOpts{
// engine.graph: nil, // obj.Graph(): nil,
// }, // },
//} //}
//if err := gv.Exec(); err != nil { //if err := gv.Exec(); err != nil {

View File

@@ -115,6 +115,10 @@ func (obj *testGraphAPI) FindEdge(f1, f2 interfaces.Func) *interfaces.FuncEdge {
return fe return fe
} }
func (obj *testGraphAPI) Graph() *pgraph.Graph {
return obj.graph.Copy()
}
type testNullFunc struct { type testNullFunc struct {
name string name string
} }

View File

@@ -262,6 +262,9 @@ type GraphAPI interface {
HasVertex(Func) bool HasVertex(Func) bool
FindEdge(Func, Func) *FuncEdge FindEdge(Func, Func) *FuncEdge
LookupEdge(*FuncEdge) (Func, Func, bool) 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 // Txn is the interface that the engine graph API makes available so that