Version: 0.9.71.dev.260504
后端:
1.阶段 5 task 服务边界落地
- 新增 cmd/task 与 services/task/{dao,rpc,sv},承载 task zrpc、tasks 表迁移和 task outbox 消费边界
- 新增 gateway/client/task、shared/contracts/task 和 task port,gateway /api/v1/task/* 切到 task zrpc client
- 将 task.urgency.promote.requested handler / relay / retry loop 迁入 cmd/task,单体 worker 不再消费 task outbox
- 保留单体 Agent 残留 task 查询的 publish-only 写入能力,避免迁移期 task 事件丢失
- active-scheduler task facts / due job scanner 切到 task RPC,并移除启动期 tasks 表依赖检查
- 更新阶段 5 文档,记录 task 切流点、旧实现保留、跨域 DB 依赖缩减和下一轮建议
- 补充 task rpc 示例配置
This commit is contained in:
73
backend/shared/contracts/task/types.go
Normal file
73
backend/shared/contracts/task/types.go
Normal file
@@ -0,0 +1,73 @@
|
||||
package task
|
||||
|
||||
import "time"
|
||||
|
||||
// AddTaskRequest 是 task 服务新增任务的跨进程契约。
|
||||
//
|
||||
// 职责边界:
|
||||
// 1. 只承载 gateway 鉴权后补齐的 user_id 和前端任务字段;
|
||||
// 2. 不承载 HTTP token、幂等键或缓存语义;
|
||||
// 3. 业务校验仍由 task 服务内部完成。
|
||||
type AddTaskRequest struct {
|
||||
UserID int `json:"user_id"`
|
||||
Title string `json:"title"`
|
||||
PriorityGroup int `json:"priority_group"`
|
||||
EstimatedSections int `json:"estimated_sections"`
|
||||
DeadlineAt *time.Time `json:"deadline_at"`
|
||||
}
|
||||
|
||||
type UserRequest struct {
|
||||
UserID int `json:"user_id"`
|
||||
}
|
||||
|
||||
type CompleteTaskRequest struct {
|
||||
UserID int `json:"user_id"`
|
||||
TaskID int `json:"task_id"`
|
||||
}
|
||||
|
||||
type UndoCompleteTaskRequest struct {
|
||||
UserID int `json:"user_id"`
|
||||
TaskID int `json:"task_id"`
|
||||
}
|
||||
|
||||
type DeleteTaskRequest struct {
|
||||
UserID int `json:"user_id"`
|
||||
TaskID int `json:"task_id"`
|
||||
}
|
||||
|
||||
type UpdateTaskRequest struct {
|
||||
UserID int `json:"user_id"`
|
||||
TaskID int `json:"task_id"`
|
||||
Title *string `json:"title"`
|
||||
PriorityGroup *int `json:"priority_group"`
|
||||
DeadlineAt *time.Time `json:"deadline_at"`
|
||||
UrgencyThresholdAt *time.Time `json:"urgency_threshold_at"`
|
||||
}
|
||||
|
||||
type BatchTaskStatusRequest struct {
|
||||
UserID int `json:"user_id"`
|
||||
IDs []int `json:"ids"`
|
||||
}
|
||||
|
||||
type TaskFactRequest struct {
|
||||
UserID int `json:"user_id"`
|
||||
TaskID int `json:"task_id"`
|
||||
Now time.Time `json:"now"`
|
||||
}
|
||||
|
||||
// TaskFact 是 active-scheduler 读取 task_pool 事实时需要的最小快照。
|
||||
type TaskFact struct {
|
||||
ID int `json:"id"`
|
||||
UserID int `json:"user_id"`
|
||||
Title string `json:"title"`
|
||||
Priority int `json:"priority"`
|
||||
IsCompleted bool `json:"is_completed"`
|
||||
DeadlineAt *time.Time `json:"deadline_at,omitempty"`
|
||||
UrgencyThresholdAt *time.Time `json:"urgency_threshold_at,omitempty"`
|
||||
EstimatedSections int `json:"estimated_sections"`
|
||||
}
|
||||
|
||||
type TaskFactResponse struct {
|
||||
Task TaskFact `json:"task"`
|
||||
Found bool `json:"found"`
|
||||
}
|
||||
24
backend/shared/ports/task.go
Normal file
24
backend/shared/ports/task.go
Normal file
@@ -0,0 +1,24 @@
|
||||
package ports
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
|
||||
taskcontracts "github.com/LoveLosita/smartflow/backend/shared/contracts/task"
|
||||
)
|
||||
|
||||
// TaskCommandClient 是 gateway 调用 task 服务的最小能力集合。
|
||||
//
|
||||
// 职责边界:
|
||||
// 1. 只覆盖当前 `/api/v1/task/*` HTTP 门面需要的能力;
|
||||
// 2. 不暴露 task DAO、outbox 状态机或 active-scheduler due job 同步细节;
|
||||
// 3. 复杂响应先以 JSON 透传,避免 gateway 复制 task 内部 DTO。
|
||||
type TaskCommandClient interface {
|
||||
AddTask(ctx context.Context, req taskcontracts.AddTaskRequest) (json.RawMessage, error)
|
||||
GetUserTasks(ctx context.Context, userID int) (json.RawMessage, error)
|
||||
BatchTaskStatus(ctx context.Context, req taskcontracts.BatchTaskStatusRequest) (json.RawMessage, error)
|
||||
CompleteTask(ctx context.Context, req taskcontracts.CompleteTaskRequest) (json.RawMessage, error)
|
||||
UndoCompleteTask(ctx context.Context, req taskcontracts.UndoCompleteTaskRequest) (json.RawMessage, error)
|
||||
UpdateTask(ctx context.Context, req taskcontracts.UpdateTaskRequest) (json.RawMessage, error)
|
||||
DeleteTask(ctx context.Context, req taskcontracts.DeleteTaskRequest) (json.RawMessage, error)
|
||||
}
|
||||
Reference in New Issue
Block a user