api

package
v0.0.0-...-2fa33bc Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 27, 2026 License: Apache-2.0 Imports: 5 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

View Source
const (
	ExecConsoleStart = "TASK_FLOW::CONSOLE::START"
	ExecConsoleDone  = "TASK_FLOW::CONSOLE::DONE"
)

These markers delimit console output in stored step logs.

View Source
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.

View Source
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.

View Source
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.

View Source
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.

View Source
const MessageSeparator = "; "

Variables

View Source
var (
	ErrExecTimeOut = errors.New("forced termination by timeout")
	ErrExecKilled  = errors.New("artificial force kill")
)
View Source
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.

View Source
var ServiceName = "taskflow"

Functions

This section is empty.

Types

type Code

type Code int

Code 响应状态码

const (
	CodeSuccess Code = 0
	CodeRunning Code = iota + 1000
	CodeFailed
	CodeNoData
	CodePending
	CodePaused
	CodeSkipped
)

type ExecCode

type ExecCode int64
const (
	ExecCodeSuccess   ExecCode = 0
	ExecCodeFailed    ExecCode = -1
	ExecCodeSkipped   ExecCode = -2
	ExecCodeKilled    ExecCode = -997
	ExecCodeTimeout   ExecCode = -998
	ExecCodeSystemErr ExecCode = -999
)

func (ExecCode) Int64

func (e ExecCode) Int64() int64

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 响应的方法。

func Fail

func Fail[T any](message string) IResponse[T]

Fail 创建失败响应的便捷方法

func NewResponse

func NewResponse[T any]() IResponse[T]

NewResponse 创建新的成功响应对象。

func Success

func Success[T any](data T) IResponse[T]

Success 创建成功响应的便捷方法

func WithCode

func WithCode[T any](code Code) IResponse[T]

WithCode 创建带状态码的响应

func WithData

func WithData[T any](data T) IResponse[T]

WithData 创建带数据的成功响应

func WithError

func WithError[T any](err error) IResponse[T]

WithError 创建错误响应

type Messages

type Messages []string

Messages 消息列表类型

func (Messages) MarshalJSON

func (msgs Messages) MarshalJSON() ([]byte, error)

MarshalJSON 自定义 JSON 序列化

func (Messages) MarshalYAML

func (msgs Messages) MarshalYAML() (any, error)

MarshalYAML 自定义 YAML 序列化

func (Messages) String

func (msgs Messages) String() string

String 将消息列表转为字符串

func (*Messages) UnmarshalJSON

func (msgs *Messages) UnmarshalJSON(data []byte) error

UnmarshalJSON 自定义 JSON 反序列化

func (*Messages) UnmarshalYAML

func (msgs *Messages) UnmarshalYAML(unmarshal func(any) error) error

UnmarshalYAML 自定义 YAML 反序列化

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]) GetCode

func (r *Response[T]) GetCode() Code

GetCode 获取状态码

func (*Response[T]) GetData

func (r *Response[T]) GetData() T

GetData 获取数据

func (*Response[T]) WithCode

func (r *Response[T]) WithCode(code Code) IResponse[T]

WithCode 设置业务状态码。

func (*Response[T]) WithData

func (r *Response[T]) WithData(data T) IResponse[T]

WithData 设置响应数据

func (*Response[T]) WithError

func (r *Response[T]) WithError(err error) IResponse[T]

WithError 设置错误信息

func (*Response[T]) WithMessage

func (r *Response[T]) WithMessage(msg string) IResponse[T]

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.

Directories

Path Synopsis
Package iproto defines API payloads, internal RPC messages, and task configuration schemas.
Package iproto defines API payloads, internal RPC messages, and task configuration schemas.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL