Skip to content

Commit

Permalink
refactor: Move GetMatchID to parent for reuse
Browse files Browse the repository at this point in the history
We will also want this helper function in the database implementation.
  • Loading branch information
bgins committed Nov 21, 2024
1 parent 24b4ef6 commit 02e018a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
8 changes: 2 additions & 6 deletions pkg/solver/store/memory/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,6 @@ type SolverStoreMemory struct {
logWriters map[string]jsonl.Writer
}

func getMatchID(resourceOffer string, jobOffer string) string {
return fmt.Sprintf("%s-%s", resourceOffer, jobOffer)
}

func NewSolverStoreMemory() (*SolverStoreMemory, error) {
logWriters := make(map[string]jsonl.Writer)

Expand Down Expand Up @@ -84,7 +80,7 @@ func (s *SolverStoreMemory) AddResult(result data.Result) (*data.Result, error)
func (s *SolverStoreMemory) AddMatchDecision(resourceOffer string, jobOffer string, deal string, result bool) (*data.MatchDecision, error) {
s.mutex.Lock()
defer s.mutex.Unlock()
id := getMatchID(resourceOffer, jobOffer)
id := store.GetMatchID(resourceOffer, jobOffer)
_, ok := s.matchDecisionMap[id]
if ok {
return nil, fmt.Errorf("that match already exists")
Expand Down Expand Up @@ -235,7 +231,7 @@ func (s *SolverStoreMemory) GetResult(id string) (*data.Result, error) {
func (s *SolverStoreMemory) GetMatchDecision(resourceOffer string, jobOffer string) (*data.MatchDecision, error) {
s.mutex.RLock()
defer s.mutex.RUnlock()
id := getMatchID(resourceOffer, jobOffer)
id := store.GetMatchID(resourceOffer, jobOffer)
decision, ok := s.matchDecisionMap[id]
if !ok {
return nil, nil
Expand Down
10 changes: 9 additions & 1 deletion pkg/solver/store/store.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package store

import "github.com/lilypad-tech/lilypad/pkg/data"
import (
"fmt"

"github.com/lilypad-tech/lilypad/pkg/data"
)

type GetJobOffersQuery struct {
JobCreator string `json:"job_creator"`
Expand Down Expand Up @@ -70,3 +74,7 @@ type SolverStore interface {
RemoveJobOffer(id string) error
RemoveResourceOffer(id string) error
}

func GetMatchID(resourceOffer string, jobOffer string) string {
return fmt.Sprintf("%s-%s", resourceOffer, jobOffer)
}

0 comments on commit 02e018a

Please sign in to comment.