feat(runner): implement cluster mode with Redis-based task dispatching and registry
Introduce a distributed task execution system for gRPC runners. This includes: - A `TaskBus` for cluster-mode task dispatching via Redis Pub/Sub. - A `RunnerRegistry` to track active runner instances in Redis. - Support for both standalone and cluster modes via configuration. - Refactored `RunnerHub` and `TaskManager` to use a `TaskDispatcher` interface, decoupling task submission from local execution. - Added distributed locking to `HotRankWorker` to ensure only one instance performs periodic hot rank recalculations in a multi-instance deployment. - Updated dependency injection (Wire) to support the new runner components and registry.
This commit is contained in:
28
internal/config/runner.go
Normal file
28
internal/config/runner.go
Normal file
@@ -0,0 +1,28 @@
|
||||
package config
|
||||
|
||||
// RunnerConfig Runner 集群配置
|
||||
type RunnerConfig struct {
|
||||
Mode string `mapstructure:"mode"` // "standalone" | "cluster",空则跟随 websocket.mode
|
||||
Cluster RunnerClusterConfig `mapstructure:"cluster"`
|
||||
}
|
||||
|
||||
// RunnerClusterConfig Runner 集群模式配置
|
||||
type RunnerClusterConfig struct {
|
||||
InstanceID string `mapstructure:"instance_id"` // 空则跟随 websocket.cluster.instance_id
|
||||
TaskChannel string `mapstructure:"task_channel"`
|
||||
ResultChannel string `mapstructure:"result_channel"`
|
||||
RegistryPrefix string `mapstructure:"registry_prefix"`
|
||||
CapPrefix string `mapstructure:"cap_prefix"`
|
||||
RegistryTTL int `mapstructure:"registry_ttl"`
|
||||
HeartbeatInterval int `mapstructure:"heartbeat_interval"`
|
||||
}
|
||||
|
||||
// ApplyWSDefaults 用 WebSocket 配置填充 Runner 中未设置的共享字段
|
||||
func (r *RunnerConfig) ApplyWSDefaults(ws WSConfig) {
|
||||
if r.Mode == "" {
|
||||
r.Mode = ws.Mode
|
||||
}
|
||||
if r.Cluster.InstanceID == "" {
|
||||
r.Cluster.InstanceID = ws.Cluster.InstanceID
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user