2021-02-25 17:46:40 -08:00
|
|
|
package worker
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2021-02-26 10:41:42 -08:00
|
|
|
"log"
|
2021-02-25 17:46:40 -08:00
|
|
|
|
|
|
|
gs "git.dragonheim.net/dragonheim/gagent/src/gstructs"
|
2021-05-23 08:42:29 -07:00
|
|
|
|
2021-05-21 23:03:50 +00:00
|
|
|
// picol "git.dragonheim.net/dragonheim/gagent/src/picol"
|
2021-02-25 17:46:40 -08:00
|
|
|
zmq "github.com/pebbe/zmq4"
|
|
|
|
)
|
|
|
|
|
2021-05-21 23:03:50 +00:00
|
|
|
// Main is the initiation function for a Worker
|
|
|
|
func Main(config gs.GagentConfig, rid int) {
|
|
|
|
log.Printf("[INFO] Starting worker\n")
|
2021-02-25 17:46:40 -08:00
|
|
|
|
2021-05-21 23:03:50 +00:00
|
|
|
// Generate connect string for this router.
|
|
|
|
var rport = int64(config.WorkerPort)
|
|
|
|
if config.Routers[rid].WorkerPort != 0 {
|
|
|
|
rport = config.Routers[rid].WorkerPort
|
2021-02-25 17:46:40 -08:00
|
|
|
}
|
2021-05-21 23:03:50 +00:00
|
|
|
connectString := fmt.Sprintf("tcp://%s:%d", config.Routers[rid].RouterAddr, rport)
|
2021-02-26 10:41:42 -08:00
|
|
|
|
2021-05-21 23:03:50 +00:00
|
|
|
subscriber, _ := zmq.NewSocket(zmq.REP)
|
|
|
|
defer subscriber.Close()
|
2021-02-26 10:41:42 -08:00
|
|
|
|
2021-05-21 23:03:50 +00:00
|
|
|
log.Printf("[DEBUG] Attempting to connect to %s\n", connectString)
|
|
|
|
subscriber.Connect(connectString)
|
2021-02-26 10:41:42 -08:00
|
|
|
|
2021-05-21 23:03:50 +00:00
|
|
|
msg, err := subscriber.Recv(0)
|
|
|
|
if err != nil {
|
2021-05-30 17:15:46 +00:00
|
|
|
log.Printf("[DEBUG] Received error: %v", err)
|
2021-02-26 10:41:42 -08:00
|
|
|
}
|
2021-05-30 22:29:16 +00:00
|
|
|
log.Printf("[DEBUG] Received message: %v", msg[0])
|
2021-02-26 10:41:42 -08:00
|
|
|
}
|