Esempio n. 1
0
// NewAMQPCanceller creates a new AMQPCanceller. No network traffic
// occurs until you call Run()
func NewAMQPCanceller(ctx gocontext.Context, conn *amqp.Connection) *AMQPCanceller {
	ctx = context.FromComponent(ctx, "canceller")

	return &AMQPCanceller{
		ctx:       ctx,
		conn:      conn,
		cancelMap: make(map[uint64](chan<- struct{})),
	}
}
Esempio n. 2
0
func newAMQPLogWriter(ctx gocontext.Context, conn *amqp.Connection, jobID uint64) (*amqpLogWriter, error) {
	channel, err := conn.Channel()
	if err != nil {
		return nil, err
	}

	err = channel.ExchangeDeclare("reporting", "topic", true, false, false, false, nil)
	if err != nil {
		return nil, err
	}

	_, err = channel.QueueDeclare("reporting.jobs.logs", true, false, false, false, nil)
	if err != nil {
		return nil, err
	}

	err = channel.QueueBind("reporting.jobs.logs", "reporting.jobs.logs", "reporting", false, nil)
	if err != nil {
		return nil, err
	}

	writer := &amqpLogWriter{
		ctx:       context.FromComponent(ctx, "log_writer"),
		amqpConn:  conn,
		amqpChan:  channel,
		jobID:     jobID,
		closeChan: make(chan struct{}),
		buffer:    new(bytes.Buffer),
		timer:     time.NewTimer(time.Hour),
		timeout:   0,
	}

	context.LoggerFromContext(ctx).WithFields(logrus.Fields{
		"writer": writer,
		"job_id": jobID,
	}).Debug("created new log writer")

	go writer.flushRegularly()

	return writer, nil
}
Esempio n. 3
0
// NewFileCanceller creates a *FileCanceller
func NewFileCanceller(ctx gocontext.Context, baseDir string) *FileCanceller {
	return &FileCanceller{
		baseDir: baseDir,
		ctx:     context.FromComponent(ctx, "canceller"),
	}
}