package main
import (
"github.com/kcotugno/tacitus"
"time"
)
type validator struct {
db tacitus.DatabaseClientService
logger tacitus.Logger
ticker *time.Ticker
done chan bool
}
func (v *validator) stop() {
if v.ticker == nil || v.done == nil {
v.ticker.Stop()
v.done <- true
func (v *validator) validate(products ...string) {
v.ticker = time.NewTicker(10 * time.Minute)
v.done = make(chan bool)
go func() {
v.emit_products(products...)
var done bool
for !done {
select {
case <-v.done:
done = true
case <-v.ticker.C:
v.ticker = nil
v.done = nil
}()
func (v *validator) emitProducts(products ...string) {
for _, p := range products {
go v.validate_product(p)
func (v *validator) validateProduct(product string) {
v.logger.Info("Staring validation of %v", product)
results, err := v.db.TradeService().TradesAfterAll(product, 0)
if err != nil {
v.logger.Info("Error getting all trades: %v", err)
var trade tacitus.Trade
current := 0
missing := [][]int{}
for results.Next() {
trade = results.Value().(tacitus.Trade)
if trade.TradeId != current+1 {
missing = append(missing, []int{current + 1, trade.TradeId - 1})
current = trade.TradeId
for _, i := range missing {
v.logger.Info("%v", i)
v.logger.Info("DONE: %v", product)