Skip to content
This repository was archived by the owner on Jun 2, 2023. It is now read-only.

Commit 4c1e89d

Browse files
committed
worker: fist lock for reporting
1 parent 08f6048 commit 4c1e89d

File tree

2 files changed

+24
-6
lines changed

2 files changed

+24
-6
lines changed

pkg/worker/analyze/processors/basic_pull_processor.go

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"github.com/golangci/golangci-api/pkg/worker/lib/github"
2121
"github.com/golangci/golangci-api/pkg/worker/lib/goutils/workspaces"
2222
"github.com/pkg/errors"
23+
redsync "gopkg.in/redsync.v1"
2324

2425
"github.com/golangci/golangci-api/internal/shared/config"
2526
envbuildresult "github.com/golangci/golangci-api/pkg/goenvbuild/result"
@@ -31,12 +32,13 @@ const (
3132
)
3233

3334
type StaticBasicPullConfig struct {
34-
RepoFetcher fetchers.Fetcher
35-
Linters []linters.Linter
36-
Runner linters.Runner
37-
ProviderClient github.Client
38-
State prstate.Storage
39-
Cfg config.Config
35+
RepoFetcher fetchers.Fetcher
36+
Linters []linters.Linter
37+
Runner linters.Runner
38+
ProviderClient github.Client
39+
State prstate.Storage
40+
Cfg config.Config
41+
DistLockFactory *redsync.Redsync
4042
}
4143

4244
type BasicPullConfig struct {
@@ -177,6 +179,12 @@ func (p *BasicPull) analyze(ctx *PullContext) (*result.Result, error) {
177179
issues := res.Issues
178180
ctx.LogCtx["reportedIssues"] = len(issues)
179181

182+
lock := p.DistLockFactory.NewMutex(ctx.ProviderCtx.Repo.FullName())
183+
if err = lock.Lock(); err != nil {
184+
return nil, errors.Wrapf(err, "failed to acquire lock %s", ctx.ProviderCtx.Repo.FullName())
185+
}
186+
defer lock.Unlock()
187+
180188
if err = p.Reporter.Report(ctx.Ctx, ctx.buildConfig, ctx.res.buildLog, ctx.pull.GetHead().GetSHA(), issues); err != nil {
181189
if errors.Cause(err) == github.ErrUserIsBlocked {
182190
return nil, &errorutils.InternalError{

pkg/worker/analyze/processors/basic_pull_processor_factory.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ package processors
22

33
import (
44
"github.com/golangci/golangci-api/internal/shared/config"
5+
"github.com/golangci/golangci-api/internal/shared/db/redis"
6+
redsync "gopkg.in/redsync.v1"
57

68
"github.com/pkg/errors"
79

@@ -86,5 +88,13 @@ func (pf BasicPullProcessorFactory) BuildProcessor(ctx *PullContext) (PullProces
8688
}))
8789
}
8890

91+
if cfg.DistLockFactory == nil {
92+
redisPool, err := redis.GetPool(cfg.Cfg)
93+
if err != nil {
94+
ctx.Log.Fatalf("Can't get redis pool: %s", err)
95+
}
96+
cfg.DistLockFactory = redsync.New([]redsync.Pool{redisPool})
97+
}
98+
8999
return NewBasicPull(&cfg), cleanup, nil
90100
}

0 commit comments

Comments
 (0)