Esempio n. 1
0
func (this *Handler) persistPendingDocuments() {
	this.waiter.Add(len(this.pending))
	metrics.Measure(DocumentsToSave, int64(len(this.pending)))

	for _, document := range this.pending {
		go this.persist(document)
	}

	this.waiter.Wait()
}
Esempio n. 2
0
func (this *Handler) Listen() {
	for message := range this.input {
		metrics.Measure(DepthPersistQueue, int64(len(this.input)))

		this.addToBatch(message)

		if len(this.input) == 0 {
			this.handleCurrentBatch(message.Receipt)
		}
	}

	close(this.output)
}
Esempio n. 3
0
func (this *Handler) Listen() {
	for message := range this.input {
		now := this.clock.UTCNow()

		metrics.Measure(transformQueueDepth, int64(len(this.input)))

		this.transformer.TransformAllDocuments(message.Message, now)

		if len(this.input) == 0 {
			this.output <- projector.DocumentMessage{
				Receipt:   message.Receipt,
				Documents: this.transformer.Collect(),
			}
		}
	}

	close(this.output)
}
Esempio n. 4
0
func (this *Handler) persist(document projector.Document) {
	started := clock.UTCNow()
	this.writer.Write(document)
	metrics.Measure(DocumentWriteLatency, milliseconds(time.Since(started)))
	this.waiter.Done()
}