This commit is contained in:
@@ -6,6 +6,8 @@ import (
|
||||
"strings"
|
||||
"sync/atomic"
|
||||
"time"
|
||||
|
||||
"github.com/break/junhong_cmp_fiber/pkg/constants"
|
||||
)
|
||||
|
||||
// globalConfig 保存当前配置,支持原子访问
|
||||
@@ -27,6 +29,7 @@ type Config struct {
|
||||
Gateway GatewayConfig `mapstructure:"gateway"`
|
||||
PollingAutoTrigger PollingAutoTriggerConfig `mapstructure:"polling_auto_trigger"`
|
||||
Polling PollingConfig `mapstructure:"polling"`
|
||||
Worker WorkerConfig `mapstructure:"worker"`
|
||||
}
|
||||
|
||||
// ServerConfig HTTP 服务器配置
|
||||
@@ -147,6 +150,12 @@ type GatewayConfig struct {
|
||||
Timeout int `mapstructure:"timeout"` // 超时时间(秒)
|
||||
}
|
||||
|
||||
// WorkerConfig Worker 进程运行配置
|
||||
type WorkerConfig struct {
|
||||
Role string `mapstructure:"role"` // Worker 运行角色:all、leader、consumer
|
||||
InstanceName string `mapstructure:"instance_name"` // Worker 实例名称,用于多实例日志区分
|
||||
}
|
||||
|
||||
// PollingConfig 轮询通用配置
|
||||
type PollingConfig struct {
|
||||
// VerboseLog 开启后,所有轮询 handler 在成功获取上游数据时以 Info 级别输出详细日志
|
||||
@@ -320,6 +329,21 @@ func (c *Config) Validate() error {
|
||||
}
|
||||
}
|
||||
|
||||
validWorkerRoles := map[string]bool{
|
||||
constants.WorkerRoleAll: true,
|
||||
constants.WorkerRoleLeader: true,
|
||||
constants.WorkerRoleConsumer: true,
|
||||
}
|
||||
if !validWorkerRoles[c.Worker.Role] {
|
||||
return fmt.Errorf(
|
||||
"invalid configuration: worker.role: invalid worker role (current value: %s, expected: %s, %s, %s)",
|
||||
c.Worker.Role,
|
||||
constants.WorkerRoleAll,
|
||||
constants.WorkerRoleLeader,
|
||||
constants.WorkerRoleConsumer,
|
||||
)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@@ -125,3 +125,7 @@ polling_auto_trigger:
|
||||
enable_auto_trigger: true
|
||||
auto_trigger_system_user_id: 1 # 暂用 SuperAdmin,生产环境建议创建专用平台账号并更新此值
|
||||
|
||||
# Worker 运行配置
|
||||
worker:
|
||||
role: "all"
|
||||
instance_name: ""
|
||||
|
||||
@@ -118,6 +118,8 @@ func bindEnvVariables(v *viper.Viper) {
|
||||
"gateway.app_id",
|
||||
"gateway.app_secret",
|
||||
"gateway.timeout",
|
||||
"worker.role",
|
||||
"worker.instance_name",
|
||||
"wechat.official_account.app_id",
|
||||
"wechat.official_account.app_secret",
|
||||
"wechat.official_account.token",
|
||||
|
||||
11
pkg/constants/worker.go
Normal file
11
pkg/constants/worker.go
Normal file
@@ -0,0 +1,11 @@
|
||||
package constants
|
||||
|
||||
// Worker 角色常量
|
||||
const (
|
||||
// WorkerRoleAll 兼容单实例模式,启动全部 Worker 模块
|
||||
WorkerRoleAll = "all"
|
||||
// WorkerRoleLeader 单例调度模式,启动全部 Worker 模块
|
||||
WorkerRoleLeader = "leader"
|
||||
// WorkerRoleConsumer 消费者模式,只启动队列消费相关模块
|
||||
WorkerRoleConsumer = "consumer"
|
||||
)
|
||||
Reference in New Issue
Block a user