Skip to content

Commit 6fdaa09

Browse files
committed
fix: Add retry on locks
1 parent 346a4d8 commit 6fdaa09

12 files changed

+396
-269
lines changed

cmd/server.go

+9
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ const (
113113
APISecretFlag = "api-secret"
114114
HidePrevPlanComments = "hide-prev-plan-comments"
115115
QuietPolicyChecks = "quiet-policy-checks"
116+
LockAcquireTimeoutSeconds = "lock-acquire-timeout"
116117
LockingDBType = "locking-db-type"
117118
LogLevelFlag = "log-level"
118119
MarkdownTemplateOverridesDirFlag = "markdown-template-overrides-dir"
@@ -173,6 +174,7 @@ const (
173174
DefaultGiteaBaseURL = "https://gitea.com"
174175
DefaultGiteaPageSize = 30
175176
DefaultGitlabHostname = "gitlab.com"
177+
DefaultLockAcquireTimeoutSeconds = 900
176178
DefaultLockingDBType = "boltdb"
177179
DefaultLogLevel = "info"
178180
DefaultMaxCommentsPerCommand = 100
@@ -607,6 +609,10 @@ var intFlags = map[string]intFlag{
607609
" If merge base is further behind than this number of commits from any of branches heads, full fetch will be performed.",
608610
defaultValue: DefaultCheckoutDepth,
609611
},
612+
LockAcquireTimeoutSeconds: {
613+
description: fmt.Sprintf("The number of seconds to wait for a lock to be acquired before timing out. The default value is %d", DefaultLockAcquireTimeoutSeconds),
614+
defaultValue: DefaultLockAcquireTimeoutSeconds,
615+
},
610616
MaxCommentsPerCommand: {
611617
description: "If non-zero, the maximum number of comments to split command output into before truncating.",
612618
defaultValue: DefaultMaxCommentsPerCommand,
@@ -930,6 +936,9 @@ func (s *ServerCmd) setDefaults(c *server.UserConfig, v *viper.Viper) {
930936
if c.AutoDiscoverModeFlag == "" {
931937
c.AutoDiscoverModeFlag = DefaultAutoDiscoverMode
932938
}
939+
if c.LockAcquireTimeoutSeconds == 0 {
940+
c.LockAcquireTimeoutSeconds = DefaultLockAcquireTimeoutSeconds
941+
}
933942
}
934943

935944
func (s *ServerCmd) validate(userConfig server.UserConfig) error {

server/controllers/events/events_controller_e2e_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1347,7 +1347,7 @@ func setupE2E(t *testing.T, repoDir string, opt setupOption) (events_controllers
13471347
}
13481348

13491349
defaultTFVersion := terraformClient.DefaultVersion()
1350-
locker := events.NewDefaultWorkingDirLocker()
1350+
locker := events.NewDefaultWorkingDirLocker(1)
13511351
parser := &config.ParserValidator{}
13521352

13531353
globalCfgArgs := valid.GlobalCfgArgs{

server/controllers/locks_controller_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ func TestDeleteLock_UpdateProjectStatus(t *testing.T) {
280280
cp := vcsmocks.NewMockClient()
281281
l := mocks2.NewMockDeleteLockCommand()
282282
workingDir := mocks2.NewMockWorkingDir()
283-
workingDirLocker := events.NewDefaultWorkingDirLocker()
283+
workingDirLocker := events.NewDefaultWorkingDirLocker(1)
284284
pull := models.PullRequest{
285285
BaseRepo: models.Repo{FullName: repoName},
286286
}
@@ -345,7 +345,7 @@ func TestDeleteLock_CommentFailed(t *testing.T) {
345345
}, nil)
346346
cp := vcsmocks.NewMockClient()
347347
workingDir := mocks2.NewMockWorkingDir()
348-
workingDirLocker := events.NewDefaultWorkingDirLocker()
348+
workingDirLocker := events.NewDefaultWorkingDirLocker(1)
349349
var backend locking.Backend
350350
tmp := t.TempDir()
351351
backend, err := db.New(tmp)
@@ -372,7 +372,7 @@ func TestDeleteLock_CommentSuccess(t *testing.T) {
372372
cp := vcsmocks.NewMockClient()
373373
dlc := mocks2.NewMockDeleteLockCommand()
374374
workingDir := mocks2.NewMockWorkingDir()
375-
workingDirLocker := events.NewDefaultWorkingDirLocker()
375+
workingDirLocker := events.NewDefaultWorkingDirLocker(1)
376376
var backend locking.Backend
377377
tmp := t.TempDir()
378378
backend, err := db.New(tmp)

server/events/delete_lock_command_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ func TestDeleteLock_Success(t *testing.T) {
4343
l := lockmocks.NewMockLocker()
4444
When(l.Unlock("id")).ThenReturn(&models.ProjectLock{}, nil)
4545
workingDir := events.NewMockWorkingDir()
46-
workingDirLocker := events.NewDefaultWorkingDirLocker()
46+
workingDirLocker := events.NewDefaultWorkingDirLocker(1)
4747
workspace := "workspace"
4848
path := "path"
4949
projectName := ""

0 commit comments

Comments
 (0)