Files
huang c665f32976
All checks were successful
构建并部署到测试环境(无 SSH) / build-and-deploy (push) Successful in 6m54s
feat: 套餐系统升级 - Worker 重构、流量重置、文档与规范更新
- 重构 Worker 启动流程,引入 bootstrap 模块统一管理依赖注入
- 实现套餐流量重置服务(日/月/年周期重置)
- 新增套餐激活排队、加油包绑定、囤货待实名激活逻辑
- 新增订单创建幂等性防重(Redis 业务键 + 分布式锁)
- 更新 AGENTS.md/CLAUDE.md:新增注释规范、幂等性规范,移除测试要求
- 添加套餐系统升级完整文档(API文档、使用指南、功能总结、运维指南)
- 归档 OpenSpec package-system-upgrade 变更,同步 specs 到主目录
- 新增 queue types 抽象和 Redis 常量定义
2026-02-12 14:24:15 +08:00

57 lines
1.6 KiB
Go
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package bootstrap
import (
"github.com/hibiken/asynq"
"github.com/redis/go-redis/v9"
"go.uber.org/zap"
"gorm.io/gorm"
"github.com/break/junhong_cmp_fiber/internal/gateway"
"github.com/break/junhong_cmp_fiber/pkg/queue"
"github.com/break/junhong_cmp_fiber/pkg/storage"
)
// WorkerDependencies Worker 进程的基础依赖
type WorkerDependencies struct {
DB *gorm.DB
Redis *redis.Client
Logger *zap.Logger
AsynqClient *asynq.Client // Worker 特有:用于 Scheduler 提交任务
StorageService *storage.Service // 对象存储(可选)
GatewayClient *gateway.Client // Gateway 客户端(可选)
}
// WorkerBootstrapResult Worker Bootstrap 初始化结果
type WorkerBootstrapResult = queue.WorkerBootstrapResult
// WorkerStores 导出的 Worker Store 集合
type WorkerStores = queue.WorkerStores
// WorkerServices 导出的 Worker 服务集合
type WorkerServices = queue.WorkerServices
// BootstrapWorker 初始化 Worker 进程的所有组件
//
// 初始化顺序:
// 1. 初始化 Worker Store 层(数据访问)
// 2. 初始化 Worker Service 层(业务逻辑)
//
// 参数:
// - deps: Worker 基础依赖DB, Redis, Logger, AsynqClient, StorageService, GatewayClient
//
// 返回:
// - *WorkerBootstrapResult: 包含 Stores 和 Services
// - error: 初始化错误
func BootstrapWorker(deps *WorkerDependencies) (*WorkerBootstrapResult, error) {
// 1. 初始化 Worker Store 层
stores := initWorkerStores(deps)
// 2. 初始化 Worker Service 层
services := initWorkerServices(stores, deps)
return &WorkerBootstrapResult{
Stores: stores,
Services: services,
}, nil
}