Created
December 20, 2022 16:20
-
-
Save jacobweinstock/fd64233fae49ab9ac1234a6d31e453a1 to your computer and use it in GitHub Desktop.
tink server state machine
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
server | |
┌────────────────────────────────────────────────────────────────────────────────────────────────────┐ | |
│ next │ | |
│ ┌────────────────────────────────────────────────┐ │ | |
│ │ │ │ | |
│ ▼ │ │ | |
│ ┌───────────┐ ┌──────────┐ ┌─────┴─────┐ ┌──────────┐ │ | |
│ │ │ │ │ success │ │ end │ │ │ | |
────────► │ pending ├───────────► │ running ├─┬───────► │ success ├─────────►│ complete │ │ | |
│ │ │ received │ │ │ │ │ │ │ │ | |
│ │ │ │ │ │ └─────┬─────┘ └──────────┘ │ | |
│ └───┬───────┘ └──────────┘ │ │ │ | |
│ │ │ │failed-builtin │ | |
│ │ │ ▼ │ | |
│ │ │ ┌───────────┐ │ | |
│ │ │ │ │ │ | |
│ │ └───────► │ failed │ │ | |
│ │ failure │ │ │ | |
│ │ └───────────┘ │ | |
│ │ │ | |
│ │ │ | |
│ │ │ | |
│ │ │ | |
│ │ │ | |
│ │ ┌─────────────────┐ │ | |
│ │ │ state machine │ │ | |
│ │ │ event handler │ │ | |
│ │ │ │ │ | |
│ │ │ │ │ | |
│ │ └─────────────────┘ │ | |
│ │ ▲ │ | |
│ │ │ │ | |
│ │ │ │ | |
│ ▼ │ │ | |
│ ┌────────────────┴─────────┐ │ | |
│ │ Workflow Execution │ │ | |
└─────────┴──────────────────────────┴───────────────────────────────────────────────────────────────┘ | |
▲ | |
│event | |
│ | |
gRPC Bidirectional Stream | |
│ | |
│action | |
▼ client | |
┌─────────┬──────────────────────────┬───────────────────────────────────────────────────────────────┐ | |
│ │ │ │ | |
│ └──────────────────────────┘ │ | |
│ │ | |
│ for { │ | |
│ action, err := stream.Recv() | | |
│ if err != nil { | | |
│ continue | | |
│ } | | |
│ if err := stream.Send("received"); err != nil { | | |
│ // log error | | |
│ continue | | |
│ } | | |
│ // handle built-in actions | | |
│ var builtin bool | | |
│ if action == "reboot" || action == "kexec" { | | |
│ builtin = true | | |
│ if err := stream.Send("success"); err != nil { | | |
│ // log error | | |
│ continue | | |
│ } | | |
│ } | | |
│ result, err := execute(action) | | |
│ if err != nil { | | |
│ // log error | | |
│ result = "failure" | | |
│ if builtin { | | |
│ result = "failed-builtin" | | |
│ } | | |
│ } | | |
│ if err := stream.Send(result); err != nil { | | |
│ // log error | | |
│ continue | | |
│ } | | |
│ } | | |
└────────────────────────────────────────────────────────────────────────────────────────────────────┘ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment