Documentation
¶
Overview ¶
Package temporal runs the flows of the kinds of request on Temporal: the flows a ticket launches, such as a payment once it is approved (server.Flows), and the agents' steps and the notes a stage asks for (server.Agents), whose answers it gives back to the server. The flows are the ones dandori generates for Temporal's Go SDK.
https://i2y.github.io/ringi-server/flows/ and https://i2y.github.io/ringi-server/agent-steps/ say how to use it, and DESIGN.md how it works.
Index ¶
Constants ¶
const ( // AskWorkflow is the type of the asking runs: one for each agent's step or note asked. AskWorkflow = "requests.ask" // AnswerActivity gives an asking run's answer to the server. AnswerActivity = "requests.answer" // LaunchWorkflow is the type of the launching runs: one for each work a ticket launches. LaunchWorkflow = "requests.launch" // EndedActivity tells the server what became of a launching run's flow. EndedActivity = "requests.ended" // DefaultTaskQueue is the task queue of the asking and the launching runs when Config.TaskQueue // is "". DefaultTaskQueue = "requests" )
The names this package gives Temporal.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Answerer ¶
type Answerer interface {
Answered(ctx context.Context, key server.EffectKey, a server.Answer) (server.Reply, error)
WorkEnded(ctx context.Context, key server.EffectKey, e server.WorkEnd) (server.Reply, error)
}
Answerer is where the answers go: *server.Server is one.
type AskResult ¶
type AskResult struct {
// Outcome is "moved" (the ticket took the answer) or "refused" (the ticket had gone on).
Outcome string `json:"outcome"`
// Refused is the kind of the refusal (stale, state), for "refused".
Refused string `json:"refused,omitempty"`
}
AskResult is what an asking run ends with, once the server has taken its answer.
type Config ¶
type Config struct {
// Flows are the flows the kinds launch and ask (FlowsOf).
Flows []Flow
// Workers are the flows' workers this process runs (Run), by the task queue they poll: each
// makes a generated package's worker (its NewWorker, with your own tasks and the Transport its
// agents call out through). A flow whose task queue has none here is run by another process.
Workers map[string]func(c client.Client) worker.Worker
// TaskQueue is the task queue of the asking and the launching runs, and of what they tell the
// server (default DefaultTaskQueue).
TaskQueue string
// AnswerTimeout is how long one try at telling the server an answer, or what became of a
// launched flow, may take (default one minute). A try that takes longer, or whose worker stops,
// is tried again.
AnswerTimeout time.Duration
// WorkerOptions are the options of the worker of the asking and the launching runs.
WorkerOptions worker.Options
}
Config is what a Runner is made of.
type Flow ¶
type Flow struct {
// Name is the name the kinds give the flow, which their effects name it by (a flow's `alias` in
// the kind's description).
Name string
// Kind limits the entry to one kind of request, for two kinds that give one name to two flows;
// "" is every kind.
Kind string
// Type and TaskQueue are the flow's workflow type and task queue (`workflow_type` and
// `task_queue`; the generated package's WorkflowType and TaskQueue).
Type string
TaskQueue string
// Outputs are the names of a note's outputs in the order its flow declares them (`outputs`):
// the note is given its outputs in that order (ringi's DESIGN 15). Without them, its outputs
// keep the order the run ended with them in.
Outputs []string
}
Flow is a flow the kinds name, and where Temporal runs it. FlowsOf makes them from the kinds' descriptions.
func FlowsOf ¶
FlowsOf answers the flows the kinds of request of the packages run, as the kinds' descriptions list them (types/<kind>.json: `flows`, ringi's DESIGN 12.2): a flow's Name is its `alias`, the name the kinds' effects give it; Type and TaskQueue are its `workflow_type` and `task_queue`; Outputs are the names of its `outputs`, in their order. A name every kind that lists it gives the same flow is one Flow for every kind (Kind ""); a name kinds give different flows is a Flow for each kind. A kind that gives one name two flows, in two of its versions, is an error: a launch and an ask name a flow by the kind and the name only.
type Runner ¶
type Runner struct {
// contains filtered or unexported fields
}
Runner starts the flows on Temporal for a server: it is the server's Config.Flows and Config.Agents.
func (*Runner) Ask ¶
Ask starts the asking run of an agent's step or a note, with the workflow ID "<key>/ask": it runs the flow and gives its answer to the server. A key asked before is a success. An error is the framework's to try again.
func (*Runner) CheckWorkers ¶
CheckWorkers asks Temporal whether a worker polls each task queue the runner starts runs on: the queues of Config.Flows, and Config.TaskQueue of the asking runs (Run's worker). A run on a queue no worker polls waits until one does, and its ticket with it. It asks about every queue again every 250 milliseconds, also after a question that failed, until Temporal has answered a worker on each, and then answers nil. When ctx ends first, between two questions or in the middle of one, it answers an error that names the queues it has found no worker on, by what Temporal last answered about each: with the error of the last question when that failed, and as not answered when Temporal has answered nothing about the queue. Temporal still lists a worker for some minutes after its last poll, so a worker found may have stopped since. Call it once the workers are up: after Run has started this process's, with the processes that run the others started.
func (*Runner) Launch ¶
Launch starts the launching run of a flow a ticket launches, with the workflow ID "<key>/launch": it runs the flow, with the key as its workflow ID, and tells the server what became of it (Server.WorkEnded). A key started before is a success. An error is the framework's to try again.