Change transformer.Execute to single header

This commit is contained in:
Edvard 2018-12-04 17:05:34 +01:00
parent 38c745e8c3
commit 8bebcdc064
4 changed files with 38 additions and 47 deletions

View File

@ -74,7 +74,7 @@ func (watcher *Watcher) Execute() error {
// TODO delegate log chunks to respective transformers
// Need to get the transformer name... :/
logChunk := chunkedLogs["transformerName"]
err = transformer.Execute(logChunk, missingHeaders)
err = transformer.Execute(logChunk, header)
}
}
return err

View File

@ -34,10 +34,9 @@ func (transformer LogNoteTransformer) NewLogNoteTransformer(db *postgres.DB) sha
return transformer
}
func (transformer LogNoteTransformer) Execute(logs []types.Log, missingHeaders []core.Header) error {
func (transformer LogNoteTransformer) Execute(logs []types.Log, header core.Header) error {
transformerName := transformer.Config.TransformerName
for _, header := range missingHeaders {
// No matching logs, mark the header as checked for this type of logs
if len(logs) < 1 {
err := transformer.Repository.MarkHeaderChecked(header.Id)
@ -45,8 +44,6 @@ func (transformer LogNoteTransformer) Execute(logs []types.Log, missingHeaders [
log.Printf("Error marking header as checked in %v: %v", transformerName, err)
return err
}
// Continue with the next header; nothing to persist
continue
}
models, err := transformer.Converter.ToModels(logs)
@ -60,6 +57,5 @@ func (transformer LogNoteTransformer) Execute(logs []types.Log, missingHeaders [
log.Printf("Error persisting %v record: %v", transformerName, err)
return err
}
}
return nil
}

View File

@ -34,19 +34,16 @@ func (transformer Transformer) NewTransformer(db *postgres.DB) shared.Transforme
return transformer
}
func (transformer Transformer) Execute(logs []types.Log, missingHeaders []core.Header) error {
func (transformer Transformer) Execute(logs []types.Log, header core.Header) error {
transformerName := transformer.Config.TransformerName
config := transformer.Config
for _, header := range missingHeaders {
if len(logs) < 1 {
err := transformer.Repository.MarkHeaderChecked(header.Id)
if err != nil {
log.Printf("Error marking header as checked in %v: %v", transformerName, err)
return err
}
continue
}
entities, err := transformer.Converter.ToEntities(config.ContractAbi, logs)
@ -67,7 +64,5 @@ func (transformer Transformer) Execute(logs []types.Log, missingHeaders []core.H
return err
}
}
return nil
}

View File

@ -23,7 +23,7 @@ import (
)
type Transformer interface {
Execute(logs []types.Log, missingHeaders []core.Header) error
Execute(logs []types.Log, header core.Header) error
}
type TransformerInitializer func(db *postgres.DB) Transformer