Documentation
¶
Overview ¶
Package api holds the wire types shared by the HTTP API and its clients: the response envelope and the multiplexed stream frames.
Index ¶
Constants ¶
const ( ExecConsoleStart = "TASK_FLOW::CONSOLE::START" ExecConsoleDone = "TASK_FLOW::CONSOLE::DONE" )
These markers delimit console output in stored step logs.
const ( // StreamUpdate carries a fresh value for a subscription. StreamUpdate = "update" // StreamDone ends a subscription that will not produce anything else. StreamDone = "done" // StreamError reports a failed request or a subscription that broke. StreamError = "error" // StreamResult carries the reply to a call. StreamResult = "result" )
Server-to-client frame events.
const ( // ActionSubscribe opens a long-lived subscription to a topic. ActionSubscribe = "subscribe" // ActionUnsubscribe closes the subscription opened by the request with the same ID. ActionUnsubscribe = "unsubscribe" // ActionCall invokes a one-shot method and is answered by a result or error frame. ActionCall = "call" // ActionPing is answered by an empty result frame; it checks the link is alive. ActionPing = "ping" )
Client-to-server actions of a StreamRequest.
const ( // TopicEvent streams worker events. TopicEvent = "event" // TopicSystem streams resource metrics. TopicSystem = "system" // TopicTasks streams the paged task list. TopicTasks = "tasks" // TopicTask streams one task's detail. TopicTask = "task" // TopicSteps streams the step list of a task. TopicSteps = "steps" // TopicStep streams one step's detail. TopicStep = "step" // TopicStepLog streams one step's log output. TopicStepLog = "step-log" // TopicTerminalSessions streams the live terminal sessions. TopicTerminalSessions = "terminal-sessions" // TopicTerminalWatch streams the output of one live terminal session. TopicTerminalWatch = "terminal-watch" // TopicTerminalReplay streams a recorded terminal session. TopicTerminalReplay = "terminal-replay" )
Topics a client can subscribe to over the multiplexed stream. The values are the wire names; the web UI and any other client send them verbatim.
const ( // MethodTaskCreate creates a task. MethodTaskCreate = "task.create" // MethodTaskManage pauses, resumes or kills a task. MethodTaskManage = "task.manage" // MethodTaskDelete deletes a task. MethodTaskDelete = "task.delete" // MethodTaskDump exports a task definition. MethodTaskDump = "task.dump" // MethodStepManage pauses, resumes or kills a step. MethodStepManage = "step.manage" // MethodSystemUpdate resizes the worker pool. MethodSystemUpdate = "system.update" // MethodTerminalDisconnect closes a live terminal session. MethodTerminalDisconnect = "terminal.disconnect" // MethodReplayList lists the recorded terminal sessions. MethodReplayList = "replay.list" )
One-shot calls a client can make over the multiplexed stream.
const MessageSeparator = "; "
Variables ¶
var ( ErrExecTimeOut = errors.New("forced termination by timeout") ErrExecKilled = errors.New("artificial force kill") )
var JSONDuration = json.JoinOptions( json.WithMarshalers(json.MarshalFunc(func(value time.Duration) ([]byte, error) { return json.Marshal(int64(value)) })), json.WithUnmarshalers(json.UnmarshalFunc(func(data []byte, value *time.Duration) error { if len(data) > 0 && data[0] == '"' { var text string if err := json.Unmarshal(data, &text); err != nil { return err } duration, err := time.ParseDuration(text) if err != nil { return err } *value = duration return nil } return json.Unmarshal(data, (*int64)(value)) })), )
JSONDuration is the JSON option set of the HTTP API for time.Duration: it is written as integer nanoseconds and read as either nanoseconds or a Go duration string such as "30s". Pass it to json.Marshal and json.Unmarshal when encoding requests or decoding responses that carry durations.
var ServiceName = "taskflow"
Functions ¶
This section is empty.
Types ¶
type IResponse ¶
type IResponse[T any] interface { WithCode(code Code) IResponse[T] WithError(err error) IResponse[T] WithData(data T) IResponse[T] WithMessage(msg string) IResponse[T] GetCode() Code GetData() T }
IResponse 定义构造和读取 API 响应的方法。
type Messages ¶
type Messages []string
Messages 消息列表类型
func (Messages) MarshalJSON ¶
MarshalJSON 自定义 JSON 序列化
func (Messages) MarshalYAML ¶
MarshalYAML 自定义 YAML 序列化
func (*Messages) UnmarshalJSON ¶
UnmarshalJSON 自定义 JSON 反序列化
type Response ¶
type Response[T any] struct { Code Code `json:"code" yaml:"code"` Message Messages `json:"msg" yaml:"message" swaggertype:"string"` Timestamp int64 `json:"timestamp" yaml:"timestamp"` Data T `json:"data" yaml:"data"` }
Response 是 API 响应的通用包络。
func (*Response[T]) WithMessage ¶
WithMessage 添加自定义消息
type StreamFrame ¶
type StreamFrame struct {
ID string `json:"id,omitempty"`
Topic string `json:"topic,omitempty"`
Event string `json:"event"`
Code Code `json:"code,omitzero"`
Message string `json:"message,omitempty"`
Data any `json:"data,omitempty"`
}
StreamFrame is one server-to-client frame. Sessions fill Code, Message and Data; the transport adds ID, Topic and Event.
type StreamRequest ¶
type StreamRequest struct {
ID string `json:"id"`
Action string `json:"action"`
Topic string `json:"topic"`
Method string `json:"method"`
Params jsontext.Value `json:"params"`
}
StreamRequest is one client-to-server frame. Params is passed verbatim to the topic or method that the request addresses.