Skip to content

Commit

Permalink
fix(hook): store md5 before sending event to channel (#5230)
Browse files Browse the repository at this point in the history
  • Loading branch information
sguiheux authored Jun 8, 2020
1 parent 0dc2ef8 commit 6aa8f03
Showing 1 changed file with 8 additions and 17 deletions.
25 changes: 8 additions & 17 deletions engine/hooks/gerrit.go
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ func ListenGerritStreamEvent(ctx context.Context, store cache.Store, v sdk.VCSCo

// Avoid that 2 hook uservice dispatch the same event
// Take the lock to dispatch an event
_, _ = store.Lock(lockKey, time.Minute, 100, 100)
_, _ = store.Lock(lockKey, time.Minute, 100, 10)

// compute md5
hasher := md5.New()
Expand All @@ -329,26 +329,17 @@ func ListenGerritStreamEvent(ctx context.Context, store cache.Store, v sdk.VCSCo
var existString string
b, _ := store.Get(k, &existString)
if !b {
// Dispatch event
gerritEventChan <- event
_ = store.SetWithTTL(k, md5, 300)
}
cpt := 0
for {
if err := store.Unlock(lockKey); err == nil {
break
}
if cpt > 100 {
break
}
log.Warning(ctx, "gerrit> Cannot remove event lock. Retry in 100ms")
time.Sleep(100 * time.Millisecond)
cpt++

// release lock
if err := store.Unlock(lockKey); err == nil {
log.Error(ctx, "unable to unlock %s. Waiting lock timeout", lockKey)
}
if cpt > 100 {
log.Error(ctx, "gerrit> Event lock cannot be removed.")

if !b {
gerritEventChan <- event
}
// release lock
}
}

Expand Down

0 comments on commit 6aa8f03

Please sign in to comment.