engine: resources: Add reversible API and file resource

This adds the first reversible resource (file) and the necessary engine
API hooks to make it all work. This allows a special "reversed" resource
to be added to the subsequent graph in the stream when an earlier
version "disappears". This disappearance can happen if it was previously
in an if statement that then becomes false.

It might be wise to combine the use of this meta parameter with the use
of the `realize` meta parameter to ensure that your reversed resource
actually runs at least once, if there's a chance that it might be gone
for a while.

This patch also adds a new test harness for testing resources. It
doesn't test the "live" aspect of resources, as it doesn't run Watch,
but it was designed to ensure CheckApply works as intended, and it runs
very quickly with a simplified timeline of happenings.
This commit is contained in:
James Shubin
2019-09-08 01:57:14 -04:00
parent 7e41860b28
commit 5c27a249b7
16 changed files with 1061 additions and 7 deletions

View File

@@ -706,6 +706,24 @@ func (obj *Main) Run() error {
continue
}
// XXX: can we change this into a ge.Apply operation?
// run reversals; modifies the graph
if err := obj.ge.Reversals(); err != nil {
obj.ge.Abort() // delete graph
Logf("error running the reversals: %+v", err)
continue
}
// Double check before we commit.
if err := obj.ge.Apply(func(graph *pgraph.Graph) error {
_, e := graph.TopologicalSort() // am i a dag or not?
return e
}); err != nil { // apply an operation to the new graph
obj.ge.Abort() // delete graph
Logf("error running the TopologicalSort: %+v", err)
continue
}
// TODO: do we want to do a transitive reduction?
// FIXME: run a type checker that verifies all the send->recv relationships