Documentation
¶
Overview ¶
Package mockprovider 提供可控的异步任务模拟 HTTP 服务,供 B-M1 验证用。
模拟真实外部 Provider 的 submit→poll/callback 语义,但所有行为可控:
- 延迟(模拟网络/处理耗时)
- 失败(模拟外部错误)
- 重复回调(模拟幂等测试)
三个端点:
POST /submit → {"task_id": "xxx"}
GET /poll → {"status": "pending|done", "result": {...}}
POST /callback → 触发回调(预留)
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Provider ¶
type Provider struct {
// SubmitDelay 模拟提交耗时
SubmitDelay time.Duration
// ProcessTime 模拟处理耗时(submit 后多久 poll 返回 done)
ProcessTime time.Duration
// ShouldFail 控制 /poll 是否返回错误
ShouldFail bool
// contains filtered or unexported fields
}
Provider 是一个可控的异步任务模拟器。
func (*Provider) ForceComplete ¶
ForceComplete 强制将任务标记为 done(模拟跳过等待直接完成)。
func (*Provider) ServeHTTP ¶
func (p *Provider) ServeHTTP(w http.ResponseWriter, r *http.Request)
ServeHTTP 实现 http.Handler。
func (*Provider) SetTaskBehavior ¶
func (p *Provider) SetTaskBehavior(taskID string, b TaskBehavior)
SetTaskBehavior 为指定 task 配置行为(submit 后调用)。
type Task ¶
type Task struct {
ID string `json:"id"`
Status string `json:"status"` // "pending" | "done" | "failed"
Result map[string]any `json:"result,omitempty"`
Input map[string]any `json:"input"`
CreatedAt time.Time `json:"created_at"`
DoneAt time.Time `json:"done_at,omitempty"`
}
Task 表示一个已提交的异步任务。
Click to show internal directories.
Click to hide internal directories.