后端:
1. 阶段 5 schedule 首刀服务化落地,新增 `cmd/schedule`、`services/schedule/{dao,rpc,sv,core}`、`gateway/client/schedule`、`shared/contracts/schedule` 和 schedule port
2. gateway `/api/v1/schedule/*` 切到 schedule zrpc client,HTTP 门面只保留鉴权、参数绑定、超时和轻量转发
3. active-scheduler 的 schedule facts、feedback 和 confirm apply 改为调用 schedule RPC adapter,减少对 `schedule_events`、`schedules`、`task_classes`、`task_items` 的跨域 DB 依赖
4. 单体聊天主动调度 rerun 的 schedule 读写链路切到 schedule RPC,迁移期仅保留 task facts 直读 Gorm
5. 为 schedule zrpc 补充 `Ping` 启动健康检查,并在 gateway client 与 active-scheduler adapter 初始化时校验服务可用
6. `cmd/schedule` 独立初始化 DB / Redis,只 AutoMigrate schedule 自有表,并显式检查迁移期 task / task-class 依赖表
7. 更新 active-scheduler 依赖表检查和 preview confirm apply 抽象,保留旧 Gorm 实现作为迁移期回退路径
8. 补充 `schedule.rpc` 示例配置和 schedule HTTP RPC 超时配置
文档:
1. 更新微服务迁移计划,将阶段 5 schedule 首刀进展、当前切流点、旧实现保留范围和 active-scheduler DB 依赖收缩情况写入基线
61 lines
1.5 KiB
Go
61 lines
1.5 KiB
Go
package rpc
|
|
|
|
import (
|
|
"errors"
|
|
"strings"
|
|
"time"
|
|
|
|
"github.com/LoveLosita/smartflow/backend/services/schedule/rpc/pb"
|
|
schedulesv "github.com/LoveLosita/smartflow/backend/services/schedule/sv"
|
|
"github.com/zeromicro/go-zero/core/service"
|
|
"github.com/zeromicro/go-zero/zrpc"
|
|
"google.golang.org/grpc"
|
|
)
|
|
|
|
const (
|
|
defaultListenOn = "0.0.0.0:9084"
|
|
defaultTimeout = 6 * time.Second
|
|
)
|
|
|
|
type ServerOptions struct {
|
|
ListenOn string
|
|
Timeout time.Duration
|
|
Service *schedulesv.ScheduleService
|
|
}
|
|
|
|
// NewServer 创建 schedule zrpc 服务端。
|
|
//
|
|
// 职责边界:
|
|
// 1. 只负责 zrpc server 配置与 gRPC handler 注册;
|
|
// 2. 不创建数据库、Redis 或业务服务,它们由 cmd/schedule 管理;
|
|
// 3. 返回 listenOn 供进程入口打印启动日志。
|
|
func NewServer(opts ServerOptions) (*zrpc.RpcServer, string, error) {
|
|
if opts.Service == nil {
|
|
return nil, "", errors.New("schedule service dependency not initialized")
|
|
}
|
|
|
|
listenOn := strings.TrimSpace(opts.ListenOn)
|
|
if listenOn == "" {
|
|
listenOn = defaultListenOn
|
|
}
|
|
timeout := opts.Timeout
|
|
if timeout <= 0 {
|
|
timeout = defaultTimeout
|
|
}
|
|
|
|
server, err := zrpc.NewServer(zrpc.RpcServerConf{
|
|
ServiceConf: service.ServiceConf{
|
|
Name: "schedule.rpc",
|
|
Mode: service.DevMode,
|
|
},
|
|
ListenOn: listenOn,
|
|
Timeout: int64(timeout / time.Millisecond),
|
|
}, func(grpcServer *grpc.Server) {
|
|
pb.RegisterScheduleServer(grpcServer, NewHandler(opts.Service))
|
|
})
|
|
if err != nil {
|
|
return nil, "", err
|
|
}
|
|
return server, listenOn, nil
|
|
}
|