~raymond/dialectic

b83c5500 — Raymond Douglas 5 hours ago
update module name domain
846e6c51 — Raymond Douglas 6 days ago
readme: update import references
2b2fd4db — Raymond Douglas 5 months ago
change saga name

refs

main
browse  log 

clone

read-only
https://git.sr.ht/~raymond/dialectic
read/write
git@git.sr.ht:~raymond/dialectic

You can also use your local clone with git send-email.

#dialectic

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]

#Sources

#Terminology

#DAG

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.

#Saga

Describes a single execution of a DAG, and the lifecycle of each node in the DAG.

#SEC

(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.

#Store

An optional interface for persisting saga executions.

#Installation

go get -u go.raymond.is/dialectic

#Getting started

#Defining a node

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.

#Your first saga

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()
}

#Data passage

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.

#Examples

#Trip

Inspired by McCaffrey's presentation, there is a small trip Saga to play with:

go run example/trip/main.go
Do not follow this link