浅浅升级一下
All checks were successful
构建并部署到测试环境(无 SSH) / build-and-deploy (push) Successful in 8m8s

This commit is contained in:
2026-05-06 14:41:14 +08:00
parent b0bd37ec12
commit 3a2e3f2571
16 changed files with 1490 additions and 106 deletions

View File

@@ -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
}

View File

@@ -125,3 +125,7 @@ polling_auto_trigger:
enable_auto_trigger: true
auto_trigger_system_user_id: 1 # 暂用 SuperAdmin生产环境建议创建专用平台账号并更新此值
# Worker 运行配置
worker:
role: "all"
instance_name: ""

View File

@@ -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",