Skip to content

Commit

Permalink
Rename jobKVStore to kVStore and return struct from constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
ilija42 committed Mar 12, 2024
1 parent 9f56d9b commit 2dff468
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
12 changes: 6 additions & 6 deletions core/services/job/kv_orm.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,25 +20,25 @@ type KVStore interface {
Get(key string, dest interface{}) error
}

type jobKVStore struct {
type kVStore struct {
jobID int32
q pg.Q
lggr logger.SugaredLogger
}

var _ KVStore = (*jobKVStore)(nil)
var _ KVStore = (*kVStore)(nil)

func NewJobKVStore(jobID int32, db *sqlx.DB, cfg pg.QConfig, lggr logger.Logger) KVStore {
func NewKVStore(jobID int32, db *sqlx.DB, cfg pg.QConfig, lggr logger.Logger) kVStore {
namedLogger := logger.Sugared(lggr.Named("JobORM"))
return &jobKVStore{
return kVStore{
jobID: jobID,
q: pg.NewQ(db, namedLogger, cfg),
lggr: namedLogger,
}
}

// Store saves serializable value by key.
func (kv jobKVStore) Store(key string, val interface{}) error {
func (kv kVStore) Store(key string, val interface{}) error {
jsonVal, err := json.Marshal(val)
if err != nil {
return err
Expand All @@ -58,7 +58,7 @@ func (kv jobKVStore) Store(key string, val interface{}) error {
}

// Get retrieves serializable value by key.
func (kv jobKVStore) Get(key string, dest interface{}) error {
func (kv kVStore) Get(key string, dest interface{}) error {
var ret json.RawMessage
sql := "SELECT val FROM job_kv_store WHERE id = $1 AND key = $2"
if err := kv.q.Get(&ret, sql, kv.jobID, key); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion core/services/job/kv_orm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func TestJobKVStore(t *testing.T) {
bridgesORM := bridges.NewORM(db, logger.TestLogger(t), config.Database())

jobID := int32(1337)
kvStore := job.NewJobKVStore(jobID, db, config.Database(), lggr)
kvStore := job.NewKVStore(jobID, db, config.Database(), lggr)
jobORM := NewTestORM(t, db, pipelineORM, bridgesORM, cltest.NewKeyStore(t, db, config.Database()), config.Database())

jb, err := directrequest.ValidatedDirectRequestSpec(testspecs.GetDirectRequestSpec())
Expand Down
2 changes: 1 addition & 1 deletion core/services/ocr2/delegate.go
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ func (d *Delegate) ServicesForSpec(ctx context.Context, jb job.Job) ([]job.Servi
}
lggr := logger.Sugared(d.lggr.Named(jb.ExternalJobID.String()).With(lggrCtx.Args()...))

kvStore := job.NewJobKVStore(jb.ID, d.db, d.cfg.Database(), lggr)
kvStore := job.NewKVStore(jb.ID, d.db, d.cfg.Database(), lggr)

rid, err := spec.RelayID()
if err != nil {
Expand Down

0 comments on commit 2dff468

Please sign in to comment.