Commit 1e18df0c authored by vicotor's avatar vicotor

add worker multiple config.

parent 4719dd73
...@@ -4,6 +4,7 @@ port=10001 ...@@ -4,6 +4,7 @@ port=10001
metrics_port = 28010 metrics_port = 28010
private_key = "E671C143A110C239B563F702E9F4017CA6B2B2912F675EED9AA4FED684EB30CC" private_key = "E671C143A110C239B563F702E9F4017CA6B2B2912F675EED9AA4FED684EB30CC"
standard_task_file = "standardtask.json" standard_task_file = "standardtask.json"
worker_multiple = 2
[redis] [redis]
addr="127.0.0.1:6379" addr="127.0.0.1:6379"
......
...@@ -44,12 +44,13 @@ type Config struct { ...@@ -44,12 +44,13 @@ type Config struct {
Port int `json:"port" toml:"port"` Port int `json:"port" toml:"port"`
StandardTaskFile string `json:"standard_task_file" toml:"standard_task_file"` StandardTaskFile string `json:"standard_task_file" toml:"standard_task_file"`
//Endpoint string `json:"endpoint" toml:"endpoint"` //Endpoint string `json:"endpoint" toml:"endpoint"`
MetricPort int `json:"metrics_port" toml:"metrics_port"` MetricPort int `json:"metrics_port" toml:"metrics_port"`
EnablePay bool `json:"enable_pay" toml:"enable_pay"` EnablePay bool `json:"enable_pay" toml:"enable_pay"`
Redis RedisConfig `json:"redis" toml:"redis"` WorkerMultiple int `json:"worker_multiple" toml:"worker_multiple"`
DbConfig MysqlConfig `json:"mysql" toml:"mysql"` Redis RedisConfig `json:"redis" toml:"redis"`
Tickers TickerConfig `json:"ticker" toml:"ticker"` DbConfig MysqlConfig `json:"mysql" toml:"mysql"`
Kafka KafkaConfig `json:"kafka" toml:"kafka"` Tickers TickerConfig `json:"ticker" toml:"ticker"`
Kafka KafkaConfig `json:"kafka" toml:"kafka"`
} }
var _cfg *Config = nil var _cfg *Config = nil
...@@ -90,3 +91,11 @@ func (conf *Config) ApiEndpoint() string { ...@@ -90,3 +91,11 @@ func (conf *Config) ApiEndpoint() string {
func (conf *Config) StandardTaskFilePath() string { func (conf *Config) StandardTaskFilePath() string {
return conf.StandardTaskFile return conf.StandardTaskFile
} }
func (conf *Config) GetWorkerMultiple() int {
if conf.WorkerMultiple > 0 {
return conf.WorkerMultiple
} else {
return 1
}
}
...@@ -64,9 +64,11 @@ func (wm *WorkerManager) AddWorkerFirst(worker *Worker) error { ...@@ -64,9 +64,11 @@ func (wm *WorkerManager) AddWorkerFirst(worker *Worker) error {
// add device to redis // add device to redis
priority := 0 priority := 0
_ = device // todo: set priority with device info. _ = device // todo: set priority with device info.
// add worker to redis queue for m := 0; m < config.GetConfig().GetWorkerMultiple(); m++ {
if err := wm.rdb.RPush(context.Background(), config.WORKER_QUEUE_PREFIX+strconv.Itoa(priority), workerId(worker)).Err(); err != nil { // add worker to redis queue
continue if err := wm.rdb.RPush(context.Background(), config.WORKER_QUEUE_PREFIX+strconv.Itoa(priority), workerId(worker)).Err(); err != nil {
continue
}
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment