-
Notifications
You must be signed in to change notification settings - Fork 203
/
conveyor_with_retry.go
78 lines (69 loc) · 2.31 KB
/
conveyor_with_retry.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package build
import (
"context"
"github.com/werf/werf/pkg/config"
"github.com/werf/werf/pkg/container_runtime"
"github.com/werf/werf/pkg/giterminism_manager"
"github.com/werf/werf/pkg/storage"
"github.com/werf/werf/pkg/storage/manager"
)
type ConveyorWithRetryWrapper struct {
WerfConfig *config.WerfConfig
GiterminismManager giterminism_manager.Interface
ImageNamesToProcess []string
ProjectDir string
BaseTmpDir string
SshAuthSock string
ContainerRuntime container_runtime.ContainerRuntime
StorageManager *manager.StorageManager
StorageLockManager storage.LockManager
ConveyorOptions ConveyorOptions
}
func NewConveyorWithRetryWrapper(werfConfig *config.WerfConfig, giterminismManager giterminism_manager.Interface, imageNamesToProcess []string, projectDir, baseTmpDir, sshAuthSock string, containerRuntime container_runtime.ContainerRuntime, storageManager *manager.StorageManager, storageLockManager storage.LockManager, opts ConveyorOptions) *ConveyorWithRetryWrapper {
return &ConveyorWithRetryWrapper{
WerfConfig: werfConfig,
GiterminismManager: giterminismManager,
ImageNamesToProcess: imageNamesToProcess,
ProjectDir: projectDir,
BaseTmpDir: baseTmpDir,
SshAuthSock: sshAuthSock,
ContainerRuntime: containerRuntime,
StorageManager: storageManager,
StorageLockManager: storageLockManager,
ConveyorOptions: opts,
}
}
func (wrapper *ConveyorWithRetryWrapper) Terminate() error {
return nil
}
func (wrapper *ConveyorWithRetryWrapper) WithRetryBlock(ctx context.Context, f func(c *Conveyor) error) error {
Retry:
newConveyor := NewConveyor(
wrapper.WerfConfig,
wrapper.GiterminismManager,
wrapper.ImageNamesToProcess,
wrapper.ProjectDir,
wrapper.BaseTmpDir,
wrapper.SshAuthSock,
wrapper.ContainerRuntime,
wrapper.StorageManager,
wrapper.StorageLockManager,
wrapper.ConveyorOptions,
)
if shouldRetry, err := func() (bool, error) {
defer newConveyor.Terminate(ctx)
if err := f(newConveyor); manager.ShouldResetStagesStorageCache(err) {
if err := newConveyor.StorageManager.ResetStagesStorageCache(ctx); err != nil {
return false, err
}
return true, nil
} else {
return false, err
}
}(); err != nil {
return err
} else if shouldRetry {
goto Retry
}
return nil
}