aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--cgi/servers.go4
-rw-r--r--models/persister.go13
2 files changed, 14 insertions, 3 deletions
diff --git a/cgi/servers.go b/cgi/servers.go
index 06cd72f..9d08b6c 100644
--- a/cgi/servers.go
+++ b/cgi/servers.go
@@ -115,7 +115,9 @@ func processTick(h config.Handler, output []byte, persister *models.Persister, l
if len(extractedContent) != 0 {
log.Debugf("extracted content '%s'", extractedContent)
outboxItem := models.CreateOutboxItem(h, []byte(extractedContent))
- err = persister.Store(outboxItem)
+ err = persister.StoreWithCallback(outboxItem, func() {
+ log.With("handler", h.Name).Debug("callback for save")
+ })
if err != nil {
return err
}
diff --git a/models/persister.go b/models/persister.go
index 5f79e4e..f877488 100644
--- a/models/persister.go
+++ b/models/persister.go
@@ -21,7 +21,15 @@ func NewPersister(log *zap.SugaredLogger, db *badger.DB) *Persister {
return aso
}
-func (p *Persister) Store(model model) error {
+func (p *Persister) StoreWithCallback(m model, onSave func()) error {
+ return p.storeModel(m, onSave)
+}
+
+func (p *Persister) Store(m model) error {
+ return p.storeModel(m, func() {})
+}
+
+func (p *Persister) storeModel(model model, onSave func()) error {
log := p.log.With("model", model.Name()).With("DedupKey", model.DedupKey()).With("Key", model.Key())
log.Debug("Store()")
err := p.db.View(func(txn *badger.Txn) error {
@@ -35,8 +43,9 @@ func (p *Persister) Store(model model) error {
if updateErr != nil {
return updateErr
}
- log.Debug("saving")
+ log.Debug("saving and calling storeCallback")
updateErr = p.db.Update(model.SaveDedup) // stores the sha256
+ onSave()
}
return updateErr
})