Пример #1
0
// StartMinionAdapter is the entry point for this IO adapter. It reads from the
// main ygord queue and assume all the incoming messages are minion feedbacks.
func (srv *Server) StartMinionAdapter(client *sqs.Client, queueName string) (<-chan error, error) {
	errch := make(chan error, 0)

	ch, sqserrch, err := sqschan.Incoming(client, queueName)
	if err != nil {
		return nil, err
	}

	go func() {
		for {
			select {
			case sqsmsg := <-ch:
				msg := NewMessageFromMinionSQS(sqsmsg)
				srv.InputQueue <- msg
				err := client.DeleteMessage(sqsmsg)
				if err != nil {
					errch <- err
				}
			case err := <-sqserrch:
				errch <- err
			}
		}
	}()

	return errch, nil
}
Пример #2
0
// ReceiveSQSMessageForIRC converts an SQS message to an ygor Message and feed
// it to the InputQueue if it is a valid IRC message.  The SQS message is then
// deleted.
func ReceiveSQSMessageForIRC(client *sqs.Client, sqsmsg *sqs.Message) error {
	msgs := NewMessagesFromIRCSQS(sqsmsg)

	for _, msg := range msgs {
		if msg == nil {
			log.Printf("unhandled message in line: %s", sqsmsg.Body)
		} else {
			InputQueue <- msg
		}
	}

	err := client.DeleteMessage(sqsmsg)
	if err != nil {
		return err
	}

	return nil
}