Skip to content

Commit

Permalink
update try lock
Browse files Browse the repository at this point in the history
  • Loading branch information
linhnt3400 committed Dec 9, 2024
1 parent c204c7c commit 6d17038
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion v2/internal/worker/backfiller.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"strconv"
"strings"
"sync"
"time"

"github.com/KyberNetwork/tradelogs/v2/pkg/handler"
"github.com/KyberNetwork/tradelogs/v2/pkg/parser"
Expand Down Expand Up @@ -49,7 +50,9 @@ func (w *BackFiller) Run() {

func (w *BackFiller) run() error {
// run only one process at a time
w.mu.Lock()
if !w.mu.TryLock() {
return nil
}
defer w.mu.Unlock()

for {
Expand All @@ -75,6 +78,8 @@ func (w *BackFiller) run() error {
w.l.Errorw("error when update backfill table", "block", last-1, "err", err)
return fmt.Errorf("cannot update backfill table with %d: %w", last-1, err)
}

time.Sleep(time.Second)
}
}

Expand Down

0 comments on commit 6d17038

Please sign in to comment.