mirror of
https://github.com/dragonheim/gagent.git
synced 2025-04-26 23:18:58 -07:00
Going to trigger a build and test on the cluster.
This commit is contained in:
parent
856cebb0dc
commit
802d1b0a48
4 changed files with 51 additions and 36 deletions
|
@ -5,8 +5,8 @@ type GagentConfig struct {
|
|||
Name string `hcl:"name,optional"`
|
||||
Mode string `hcl:"mode,attr"`
|
||||
UUID string `hcl:"uuid,optional"`
|
||||
ListenAddr string `hcl:"address,optional"`
|
||||
ListenPort int `hcl:"port,optional"`
|
||||
ListenAddr string `hcl:"listenaddr,optional"`
|
||||
ListenPort int `hcl:"listenport,optional"`
|
||||
Clients []*ClientDetails `hcl:"client,block"`
|
||||
Routers []*RouterDetails `hcl:"router,block"`
|
||||
Workers []*WorkerDetails `hcl:"worker,block"`
|
||||
|
@ -43,7 +43,7 @@ type RouterDetails struct {
|
|||
* which MQ router to send the agent's requests to.
|
||||
* This attempts to keep the routers unique globally.
|
||||
*/
|
||||
RouterID string `hcl:"routerid,attr"`
|
||||
RouterID string `hcl:"uuid,attr"`
|
||||
|
||||
/*
|
||||
* This is the IP Address and port that the router
|
||||
|
@ -75,7 +75,7 @@ type WorkerDetails struct {
|
|||
* send agents to. This attempts to keep the
|
||||
* workers unique globally.
|
||||
*/
|
||||
WorkerID string `hcl:"workerid,attr"`
|
||||
WorkerID string `hcl:"uuid,attr"`
|
||||
|
||||
/*
|
||||
* These tags will be passed to the router upon
|
||||
|
|
|
@ -2,7 +2,7 @@ package worker
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
// "log"
|
||||
"log"
|
||||
"math/rand"
|
||||
"time"
|
||||
|
||||
|
@ -23,34 +23,8 @@ func pop(msg []string) (head, tail []string) {
|
|||
return
|
||||
}
|
||||
|
||||
// Main is the initiation function for a Worker
|
||||
func Main(config gs.GagentConfig) {
|
||||
// Frontend socket talks to clients over TCP
|
||||
frontend, _ := zmq.NewSocket(zmq.ROUTER)
|
||||
fmt.Printf("Running in worker mode\n")
|
||||
|
||||
defer frontend.Close()
|
||||
connectString := fmt.Sprintf("tcp://%s", config.Routers[0].RouterAddr)
|
||||
frontend.Bind(connectString)
|
||||
|
||||
// Backend socket talks to workers over inproc
|
||||
backend, _ := zmq.NewSocket(zmq.DEALER)
|
||||
defer backend.Close()
|
||||
backend.Bind("inproc://backend")
|
||||
|
||||
// Launch pool of agent handlers
|
||||
for i := 0; i < 5; i++ {
|
||||
go agentHandler(i)
|
||||
}
|
||||
|
||||
// Connect backend to frontend via a proxy
|
||||
// err := zmq.Proxy(frontend, backend, nil)
|
||||
// log.Fatalln("Proxy interrupted:", err)
|
||||
}
|
||||
|
||||
// Each worker task works on one request at a time and sends a random number
|
||||
// of replies back, with random delays between replies:
|
||||
|
||||
func agentHandler(workerNum int) {
|
||||
interp := picol.InitInterp()
|
||||
interp.RegisterCoreCommands()
|
||||
|
@ -70,8 +44,35 @@ func agentHandler(workerNum int) {
|
|||
// Sleep for some fraction of a second
|
||||
time.Sleep(time.Duration(rand.Intn(1000)+1) * time.Millisecond)
|
||||
|
||||
fmt.Println(fmt.Sprintf("Worker %d: %s", workerNum, identity))
|
||||
log.Printf(fmt.Sprintf("Worker %d: %s\n", workerNum, identity))
|
||||
worker.SendMessage(identity, content)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Main is the initiation function for a Worker
|
||||
func Main(config gs.GagentConfig) {
|
||||
// Frontend socket talks to clients over TCP
|
||||
frontend, _ := zmq.NewSocket(zmq.ROUTER)
|
||||
log.Printf("Starting worker\n")
|
||||
|
||||
defer frontend.Close()
|
||||
log.Printf("Attempting to connect to: %s(%s)\n", config.Routers[0].RouterName, config.Routers[0].RouterAddr)
|
||||
connectString := fmt.Sprintf("tcp://%s", config.Routers[0].RouterAddr)
|
||||
frontend.Bind(connectString)
|
||||
|
||||
// Backend socket talks to workers over inproc
|
||||
backend, _ := zmq.NewSocket(zmq.DEALER)
|
||||
defer backend.Close()
|
||||
backend.Bind("inproc://backend")
|
||||
|
||||
// Launch pool of agent handlers
|
||||
for i := 0; i < 5; i++ {
|
||||
go agentHandler(i)
|
||||
}
|
||||
|
||||
// Connect backend to frontend via a proxy
|
||||
// err := zmq.Proxy(frontend, backend, nil)
|
||||
// log.Fatalln("Proxy interrupted:", err)
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue