Ejemplo n.º 1
0
func (o *HttpOutput) Run(or pipeline.OutputRunner, h pipeline.PluginHelper) (err error) {
	if or.Encoder() == nil {
		return errors.New("Encoder must be specified.")
	}

	var (
		e        error
		outBytes []byte
	)
	inChan := or.InChan()

	for pack := range inChan {
		outBytes, e = or.Encode(pack)
		if e != nil {
			or.UpdateCursor(pack.QueueCursor)
			pack.Recycle(fmt.Errorf("can't encode: %s", e))
			continue
		}
		if outBytes == nil {
			or.UpdateCursor(pack.QueueCursor)
			pack.Recycle(nil)
			continue
		}
		if e = o.request(or, outBytes); e != nil {
			e = pipeline.NewRetryMessageError(e.Error())
			pack.Recycle(e)
		} else {
			or.UpdateCursor(pack.QueueCursor)
			pack.Recycle(nil)
		}
	}

	return
}
func (r *RedisListOutput) ProcessMessage(pack *pipeline.PipelinePack) (err error) {
	var record []byte

	if record, err = r.runner.Encode(pack); err != nil {
		atomic.AddInt64(&r.encodingErrors, 1)
		return fmt.Errorf("can't encode: %s", err)
	}

	atomic.AddInt64(&r.processMessageCount, 1)
	if err = r.client.RPush(r.config.Key, string(record[:])).Err(); err != nil {
		atomic.AddInt64(&r.processMessageFailures, 1)
		return pipeline.NewRetryMessageError("writing to %s: %s", r.config.Address, err)
	} else {
		r.runner.UpdateCursor(pack.QueueCursor)
	}

	return nil
}
Ejemplo n.º 3
0
func (output *IrcOutput) Run(runner pipeline.OutputRunner,
	helper pipeline.PluginHelper) error {
	if runner.Encoder() == nil {
		return errors.New("Encoder required.")
	}

	output.runner = runner

	// Register callbacks to handle events
	registerCallbacks(output)

	var err error

	// Connect to the Irc Server
	err = output.Conn.Connect(output.Server)
	if err != nil {
		return fmt.Errorf("Unable to connect to irc server %s: %s",
			output.Server, err)
	}

	// Start a goroutine for recieving messages, and throttling before sending
	// to the Irc Server
	output.wg.Add(1)
	go processOutQueue(output)

	var outgoing []byte
	ok := true
	inChan := runner.InChan()
	var pack *pipeline.PipelinePack
	for ok {
		select {
		case pack, ok = <-inChan:
		case <-output.die:
			ok = false
		}
		if !ok {
			break
		}
		outgoing, err = runner.Encode(pack)
		if err != nil {
			output.runner.UpdateCursor(pack.QueueCursor)
			err = fmt.Errorf("can't encode: %s", err.Error())
			pack.Recycle(err)
			continue
		} else if outgoing != nil {
			// Send the message to each irc channel. If the out queue is full,
			// then we need to drop the message and log an error.
			sentAny := false
			for i, ircChannel := range output.Channels {
				ircMsg := IrcMsg{outgoing, ircChannel, i}
				select {
				case output.OutQueue <- ircMsg:
					sentAny = true
				default:
					output.runner.LogError(ErrOutQueueFull)
				}
			}
			if !sentAny {
				err = pipeline.NewRetryMessageError("IRC delivery failed")
				pack.Recycle(err)
				continue
			}
		}
		output.runner.UpdateCursor(pack.QueueCursor)
		pack.Recycle(nil)
	}
	output.cleanup()
	return nil
}