Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
moukoublen committed May 14, 2024
1 parent ff19585 commit 7db9e65
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
13 changes: 11 additions & 2 deletions internal/vulnerability/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,13 @@ type VulnerabilityRunner struct {
}

func NewVulnerabilityRunner(log *logp.Logger) (VulnerabilityRunner, error) {
ctx := context.Background() // TODO: carry
log.Debug("NewVulnerabilityRunner: New")

if err := clearTrivyCache(ctx, log); err != nil {
log.Warnf("error during runner cache clearing %s", err.Error())
}

opts := flag.Options{
GlobalOptions: flag.GlobalOptions{
// TODO: Make configurable
Expand All @@ -56,7 +62,7 @@ func NewVulnerabilityRunner(log *logp.Logger) (VulnerabilityRunner, error) {
},
}

runner, err := artifact.NewRunner(context.Background(), opts)
runner, err := artifact.NewRunner(ctx, opts)
if err != nil {
log.Error("NewVulnerabilityRunner: NewRunner error: ", err)
return VulnerabilityRunner{}, err
Expand All @@ -72,7 +78,8 @@ func (f VulnerabilityRunner) GetRunner() artifact.Runner {
return f.runner
}

func (f VulnerabilityRunner) ClearCache(ctx context.Context) error {
func clearTrivyCache(ctx context.Context, log *logp.Logger) error {
log.Info("Starting VulnerabilityRunner.ClearCache")
options := []flag.Options{
{CacheOptions: flag.CacheOptions{ClearCache: true}},
{DBOptions: flag.DBOptions{Reset: true}},
Expand All @@ -94,5 +101,7 @@ func (f VulnerabilityRunner) ClearCache(ctx context.Context) error {
errs = append(errs, r.Close(ctx))
}

log.Infof("Ending VulnerabilityRunner.ClearCache %d", len(errs))

return errors.Join(errs...)
}
9 changes: 1 addition & 8 deletions internal/vulnerability/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,14 +97,7 @@ func NewVulnerabilityWorker(log *logp.Logger, c *config.Config, bdp dataprovider
func (f *VulnerabilityWorker) Run(ctx context.Context) {
f.log.Info("Starting VulnerabilityWorker.work")
defer func() {
err := f.runner.ClearCache(ctx)
if err != nil {
f.log.Warnf("error during runner cache clearing %s", err.Error())
}
}()
defer func() {
err := f.runner.GetRunner().Close(ctx)
if err != nil {
if err := f.runner.GetRunner().Close(ctx); err != nil {
f.log.Warnf("error during runner closing %s", err.Error())
}
}()
Expand Down

0 comments on commit 7db9e65

Please sign in to comment.