2019-04-24 20:05:57 +00:00
|
|
|
package fetcher
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/vulcanize/vulcanizedb/libraries/shared/storage/utils"
|
|
|
|
"github.com/vulcanize/vulcanizedb/pkg/fs"
|
|
|
|
"strings"
|
|
|
|
)
|
|
|
|
|
|
|
|
type IStorageFetcher interface {
|
|
|
|
FetchStorageDiffs(chan<- utils.StorageDiffRow, chan<- error)
|
|
|
|
}
|
|
|
|
|
|
|
|
type CsvTailStorageFetcher struct {
|
|
|
|
tailer fs.Tailer
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewCsvTailStorageFetcher(tailer fs.Tailer) CsvTailStorageFetcher {
|
|
|
|
return CsvTailStorageFetcher{tailer: tailer}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (storageFetcher CsvTailStorageFetcher) FetchStorageDiffs(out chan<- utils.StorageDiffRow, errs chan<- error) {
|
|
|
|
t, tailErr := storageFetcher.tailer.Tail()
|
|
|
|
if tailErr != nil {
|
|
|
|
errs <- tailErr
|
|
|
|
}
|
|
|
|
for line := range t.Lines {
|
|
|
|
row, parseErr := utils.FromStrings(strings.Split(line.Text, ","))
|
|
|
|
if parseErr != nil {
|
|
|
|
errs <- parseErr
|
2019-04-26 15:36:42 +00:00
|
|
|
} else {
|
|
|
|
out <- row
|
2019-04-24 20:05:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|