update module name domain
readme: update import references
change saga name
In classical philosophy, dialectic (διαλεκτική) is a form of reasoning based upon dialogue of arguments and counter-arguments, advocating propositions (theses) and counter-propositions (antitheses). The outcome of such a dialectic might be the refutation of a relevant proposition, or a synthesis, a combination of the opposing assertions, or a qualitative improvement of the dialogue. [Wikipedia]
In mathematics, particularly graph theory, and computer science, a directed acyclic graph (DAG) is a directed graph with no directed cycles. That is, it consists of vertices and edges (also called arcs), with each edge directed from one vertex to another, such that following those directions will never form a closed loop. [Wikipedia]
This package's current interpretation of DAG is largely concerned with directionality and general concurrency.
Describes a single execution of a DAG, and the lifecycle of each node in the DAG.
(S)aga (E)xecution (C)oordinator
Responsible for executing a given saga, and recording the success or failure of each node in the DAG—for the purposes of properly unwinding the saga if necessary.
An optional interface for persisting saga executions.
go get -u go.raymond.is/dialectic
Each node of a DAG expects the following Action
interface to be satisfied:
Action interface {
Do() error
Undo() error
}
By providing such an interface, the SEC will dutifully execute Do()
and
Undo()
accordingly.
This saga implies that all Action
interfaces reside in the current package.
package main
import (
"go.raymond.is/dialectic/dag"
"go.raymond.is/dialectic/saga"
"go.raymond.is/dialectic/sec"
)
func main() {
// Create a new DAG
d := dag.New("iam_identity")
// Add phases (Slices of `dag.Node`) to the DAG
d.Add([]dag.Node{
// These will execute concurrently
{Name: "policy", Action: NewPolicy("<policy_name>", "<policy_json>")},
{Name: "role", Action: NewRole("<role_name>")},
})
d.Add([]dag.Node{{Name: "role_policy_attachment", Action: NewAttachment()}})
// Create a new Saga
sg := saga.New("new_iam_role")
// Create a new SEC
s := sec.New(sg, d, nil)
// Start the saga
s.Start()
}
By itself, dialectic does not make opinions nor manage passage of data between nodes and phases of the DAG during execution. It is up to the implementor to use methods appropriate for their environment.
Though, global structs/channels work quite well.
Inspired by McCaffrey's presentation, there is a small trip Saga to play with:
go run example/trip/main.go