gin logging
This commit is contained in:
@@ -16,11 +16,13 @@ type (
|
||||
logger *zap.Logger
|
||||
storage *storage.Service
|
||||
git *providers.Git
|
||||
action *actions.Action
|
||||
}
|
||||
|
||||
ProcessReposDeps interface {
|
||||
GetStorageService() *storage.Service
|
||||
GetGitProvider() *providers.Git
|
||||
GetAction() *actions.Action
|
||||
}
|
||||
)
|
||||
|
||||
@@ -29,10 +31,11 @@ func NewProcessRepos(logger *zap.Logger, deps ProcessReposDeps) *ProcessRepos {
|
||||
logger: logger,
|
||||
storage: deps.GetStorageService(),
|
||||
git: deps.GetGitProvider(),
|
||||
action: deps.GetAction(),
|
||||
}
|
||||
}
|
||||
|
||||
func (pr *ProcessRepos) Process(ctx context.Context, repositoryUrls []string, action *actions.Action) error {
|
||||
func (pr *ProcessRepos) Process(ctx context.Context, repositoryUrls []string) error {
|
||||
// Clone repos
|
||||
wg := sync.WaitGroup{}
|
||||
wg.Add(len(repositoryUrls))
|
||||
@@ -62,14 +65,32 @@ func (pr *ProcessRepos) Process(ctx context.Context, repositoryUrls []string, ac
|
||||
}(ctx)
|
||||
|
||||
pr.logger.Debug("Cloning repo", zap.String("path", area.Path), zap.String("repoUrl", repoUrl))
|
||||
ctx, _ = context.WithTimeout(ctx, time.Second*5)
|
||||
_, err = pr.git.Clone(ctx, area, repoUrl)
|
||||
cloneCtx, _ := context.WithTimeout(ctx, time.Second*5)
|
||||
_, err = pr.git.Clone(cloneCtx, area, repoUrl)
|
||||
if err != nil {
|
||||
pr.logger.Error("could not clone repo", zap.Error(err))
|
||||
errChan <- err
|
||||
return
|
||||
}
|
||||
|
||||
err = pr.action.Run(
|
||||
ctx,
|
||||
area,
|
||||
func(ctx context.Context, area *storage.Area) (bool, error) {
|
||||
pr.logger.Debug("checking predicate", zap.String("area", area.Path))
|
||||
return true, nil
|
||||
},
|
||||
func(ctx context.Context, area *storage.Area) error {
|
||||
pr.logger.Debug("running action", zap.String("area", area.Path))
|
||||
return nil
|
||||
}, false)
|
||||
|
||||
if err != nil {
|
||||
pr.logger.Error("could not run action", zap.Error(err))
|
||||
errChan <- err
|
||||
return
|
||||
}
|
||||
|
||||
pr.logger.Debug("processing done", zap.String("path", area.Path), zap.String("repoUrl", repoUrl))
|
||||
}(ctx, repoUrl)
|
||||
}
|
||||
|
Reference in New Issue
Block a user