示例#1
0
文件: main.go 项目: SalmonMode/ygor
// Loop until the end of time.
//
// In case of error, delay the next loop. Automatically reconnect if everything
// goes fine (for 0 or 1 message).
func main() {
	parseCommandLine()

	err := parseConfigFile()
	if err != nil {
		log.Fatal("config error: ", err.Error())
	}

	log.Printf("%s starting up", cfg.Name)

	// This is the message box.
	incoming := make(chan *sqs.Message)
	if cfg.TestMode {
		err := startReceivingFromStdin(incoming)
		if err != nil {
			log.Fatal(err)
		}
	} else {
		err := startReceivingFromSQS(incoming)
		if err != nil {
			log.Fatal(err)
		}
	}

	go waitForTraceRequest()

	go playNoise()

	if !cfg.TestMode {
		mplayer.StartSlave(mplayerErrorHandler)
	}

	for msg := range incoming {
		command, data := SplitTwo(sqs.SQSDecode(msg.Body))

		switch command {
		case "play", "play-tune":
			Play(data)
		case "xombrero":
			Xombrero(data)
		case "shutup":
			ShutUp()
		case "skip":
			Skip()
		case "reboot":
			Reboot()
		case "ping":
			Ping(data)
		case "volume":
			Volume(data)
		//case "turret":
		//	Turret(data)
		case "error":
			// These errors are typically received when the queue
			// systems fails to fetch a message. There is no reason
			// at the moment for ygord to send errors to minions.
			log.Printf("error message: %s", data)
		case "register":
			log.Printf("registration: %s", data)
		default:
			log.Printf("unknown command: %s", msg)
		}
	}
}
示例#2
0
// NewMessageFromMinionSQS converts an SQS message into an ygor message.
func NewMessageFromMinionSQS(sqsmsg *sqs.Message) *Message {
	msg := NewMessageFromMinionLine(sqs.SQSDecode(sqsmsg.Body))
	msg.UserID = sqsmsg.SenderID
	return msg
}