Skip to content

Commit

Permalink
Address feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
cedric-cordenier committed Sep 25, 2024
1 parent e4fc9a6 commit 6f2ad32
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 10 deletions.
7 changes: 3 additions & 4 deletions core/capabilities/compute/cache.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package compute

import (
"fmt"
"sync"
"time"

Expand Down Expand Up @@ -88,18 +87,18 @@ func (mc *moduleCache) add(id string, mod *module) {
moduleCacheAddition.Inc()
}

func (mc *moduleCache) get(id string) (*module, error) {
func (mc *moduleCache) get(id string) (*module, bool) {
mc.mu.Lock()
defer mc.mu.Unlock()
gotModule, ok := mc.m[id]
if !ok {
moduleCacheHit.WithLabelValues("false").Inc()
return nil, fmt.Errorf("could not find module for id %s", id)
return nil, false
}

moduleCacheHit.WithLabelValues("true").Inc()
gotModule.lastFetchedAt = mc.clock.Now()
return gotModule, nil
return gotModule, true
}

func (mc *moduleCache) evictOlderThan(duration time.Duration) {
Expand Down
8 changes: 4 additions & 4 deletions core/capabilities/compute/cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,13 @@ func TestCache(t *testing.T) {
}
cache.add(id, mod)

got, err := cache.get(id)
require.NoError(t, err)
got, ok := cache.get(id)
assert.True(t, ok)

assert.Equal(t, got, mod)

clock.Advance(15 * time.Second)
<-cache.onReaper
m, err := cache.get(id)
assert.ErrorContains(t, err, "could not find module", m)
_, ok = cache.get(id)
assert.False(t, ok)
}
4 changes: 2 additions & 2 deletions core/capabilities/compute/compute.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ func (c *Compute) Execute(ctx context.Context, request capabilities.CapabilityRe

id := generateID(binary)

m, err := c.modules.get(id)
if err != nil {
m, ok := c.modules.get(id)
if !ok {
mod, err := c.initModule(id, binary, request.Metadata.WorkflowID, request.Metadata.ReferenceID)
if err != nil {
return capabilities.CapabilityResponse{}, err
Expand Down

0 comments on commit 6f2ad32

Please sign in to comment.