Skip to content

Commit

Permalink
Merge pull request #224 from gianlucam76/fix
Browse files Browse the repository at this point in the history
Fix store result
  • Loading branch information
gianlucam76 authored Oct 11, 2023
2 parents 63c52ba + 33de363 commit 369b74f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
16 changes: 11 additions & 5 deletions lib/deployer/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,15 +167,15 @@ func processRequests(ctx context.Context, d *deployer, i int, logger logr.Logger
applicant, featureID, _ := getApplicatantAndFeatureFromKey(params.key)
cleanup, err := getIsCleanupFromKey(params.key)
if err != nil {
storeResult(d, params.key, err, params.handler, params.metric, logger)
storeResult(d, params.key, err, params.handlerOptions, params.handler, params.metric, logger)
} else {
l.Info(fmt.Sprintf("worker: %d processing request. cleanup: %t", id, cleanup))
start := time.Now()
l.V(logs.LogDebug).Info("invoking handler")
err = params.handler(ctx, controlClusterClient,
ns, name, applicant, featureID, clusterType, params.handlerOptions,
l)
storeResult(d, params.key, err, params.handler, params.metric, logger)
storeResult(d, params.key, err, params.handlerOptions, params.handler, params.metric, logger)
elapsed := time.Since(start)
if params.metric != nil {
params.metric(elapsed, ns, name, featureID, clusterType, l)
Expand Down Expand Up @@ -217,8 +217,8 @@ func processRequests(ctx context.Context, d *deployer, i int, logger logr.Logger
// - set results for further in time lookup
// - remove key from inProgress
// - if key is in dirty, remove it from there and add it to the back of the jobQueue
func storeResult(d *deployer, key string, err error, handler RequestHandler, metricHandler MetricHandler,
logger logr.Logger) {
func storeResult(d *deployer, key string, err error, handlerOptions Options,
handler RequestHandler, metricHandler MetricHandler, logger logr.Logger) {

d.mu.Lock()

Expand Down Expand Up @@ -247,7 +247,13 @@ func storeResult(d *deployer, key string, err error, handler RequestHandler, met
continue
}
l.V(logs.LogVerbose).Info("add to jobQueue")
d.jobQueue = append(d.jobQueue, requestParams{key: d.dirty[i], handler: handler, metric: metricHandler})
d.jobQueue = append(d.jobQueue,
requestParams{
key: d.dirty[i],
handler: handler,
metric: metricHandler,
handlerOptions: handlerOptions,
})
l.V(logs.LogVerbose).Info("remove from dirty")
d.dirty = removeFromSlice(d.dirty, i)
l.V(logs.LogVerbose).Info("remove result")
Expand Down
4 changes: 2 additions & 2 deletions lib/deployer/worker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ var _ = Describe("Worker", func() {
d.SetInProgress([]string{key})
Expect(len(d.GetInProgress())).To(Equal(1))

deployer.StoreResult(d, key, nil, doNothingHandler, metricHandler, klogr.New())
deployer.StoreResult(d, key, nil, deployer.Options{}, doNothingHandler, metricHandler, klogr.New())
Expect(len(d.GetInProgress())).To(Equal(0))
})

Expand All @@ -150,7 +150,7 @@ var _ = Describe("Worker", func() {
d.SetDirty([]string{key})
Expect(len(d.GetDirty())).To(Equal(1))

deployer.StoreResult(d, key, nil, doNothingHandler, metricHandler, klogr.New())
deployer.StoreResult(d, key, nil, deployer.Options{}, doNothingHandler, metricHandler, klogr.New())
Expect(len(d.GetInProgress())).To(Equal(0))
Expect(len(d.GetDirty())).To(Equal(0))
Expect(len(d.GetJobQueue())).To(Equal(1))
Expand Down

0 comments on commit 369b74f

Please sign in to comment.