예제 #1
0
func (outbox *PigeonOutbox) send(hostname string, request *PigeonRequest, respChan chan<- Response) error {
	resp := &PigeonResponse{}

	// Dial the server
	// TODO: Inefficient to dial each time?
	log.Info("RPC Dialing")
	rpcClient, err := rpc.DialHTTP("tcp", hostname+":1888")
	if err != nil {
		return fmt.Errorf("Pigeon: (dialing) %s", err.Error())
	}
	defer rpcClient.Close()

	// Make the call
	log.Info("RPC Calling")
	err = rpcClient.Call("PigeonServer.RPCHandleRequest", request, resp)
	if err != nil {
		log.Error("Pigeon: (calling) ", err.Error())
		// Send error response to channel
		respChan <- resp
		return fmt.Errorf("Pigeon: (calling) %s", err.Error())
	}

	// Send response to channel
	respChan <- resp

	return nil
}
예제 #2
0
func (outbox *PigeonOutbox) Launch(key string, payload map[string]interface{}) (<-chan Response, error) {
	log.Info("Launching ", key)

	req := PigeonRequest{
		ReqJobKey: key,
		ReqBody:   payload,
	}

	// Get list of all workers interested in these keys
	serverHosts, err := outbox.sys.dl.GetListeners(key)
	if err != nil {
		return nil, err
	}

	if len(serverHosts) == 0 {
		log.Info("No listeners found", key)
		return nil, fmt.Errorf("Pigeon: No listeners found for %s", key)
	}

	// For now, pick one at random
	serverHost := serverHosts[rand.Intn(len(serverHosts))]

	log.Info("Making RPC call ", key)
	respChan := make(chan Response)
	go outbox.send(serverHost, &req, respChan)
	log.Info("Returned from send", key)

	return respChan, nil
}
예제 #3
0
func main() {
	var err error
	log.Init("/var/log/odyn/server.log")

	// Spin up webserver
	rootMux := http.NewServeMux()
	launcher := webserver.NewLauncher()
	launcher.StartHTTPServer(":8080", rootMux)

	// Test storage engine
	engine := fs.NewEngine("/var/lib/odyn")
	err = engine.Prep()
	if err != nil {
		log.Error(err)
		return
	}

	conn, err := engine.Connect()
	if err != nil {
		log.Error(err)
		return
	}

	conn.Close()

	err = launcher.WaitForComplete()
	log.Info(err.Error())
}