Files
hatchet/pkg/repository/interval_settings.go
matt 058968c06b Refactor: Attempt II at removing pgtype.UUID everywhere + convert string UUIDs into uuid.UUID (#2894)
* fix: add type override in sqlc.yaml

* chore: gen sqlc

* chore: big find and replace

* chore: more

* fix: clean up bunch of outdated `.Valid` refs

* refactor: remove `sqlchelpers.uuidFromStr()` in favor of `uuid.MustParse()`

* refactor: remove uuidToStr

* fix: lint

* fix: use pointers for null uuids

* chore: clean up more null pointers

* chore: clean up a bunch more

* fix: couple more

* fix: some types on the api

* fix: incorrectly non-null param

* fix: more nullable params

* fix: more refs

* refactor: start replacing tenant id strings with uuids

* refactor: more tenant id uuid casting

* refactor: fix a bunch more

* refactor: more

* refactor: more

* refactor: is that all of them?!

* fix: panic

* fix: rm scans

* fix: unwind some broken things

* chore: tests

* fix: rebase issues

* fix: more tests

* fix: nil checks

* Refactor: Make all UUIDs into `uuid.UUID` (#2897)

* refactor: remove a bunch more string uuids

* refactor: pointers and lists

* refactor: fix all the refs

* refactor: fix a few more

* fix: config loader

* fix: revert some changes

* fix: tests

* fix: test

* chore: proto

* fix: durable listener

* fix: some more string types

* fix: python health worker sleep

* fix: remove a bunch of `MustParse`s from the various gRPC servers

* fix: rm more uuid.MustParse calls

* fix: rm mustparse from api

* fix: test

* fix: merge issues

* fix: handle a bunch more uses of `MustParse` everywhere

* fix: nil id for worker label

* fix: more casting in the oss

* fix: more id parsing

* fix: stringify jwt opt

* fix: couple more bugs in untyped calls

* fix: more types

* fix: broken test

* refactor: implement `GetKeyUuid`

* chore: regen sqlc

* chore: replace pgtype.UUID again

* fix: bunch more type errors

* fix: panic
2026-02-03 11:02:59 -05:00

98 lines
2.7 KiB
Go

package repository
import (
"context"
"errors"
"time"
"github.com/google/uuid"
"github.com/jackc/pgx/v5"
"github.com/hatchet-dev/hatchet/pkg/repository/sqlcv1"
)
type IntervalSettingsRepository interface {
ReadAllIntervals(ctx context.Context, operationId string) (map[string]time.Duration, error)
ReadInterval(ctx context.Context, operationId string, tenantId uuid.UUID) (time.Duration, error)
SetInterval(ctx context.Context, operationId string, tenantId uuid.UUID, d time.Duration) (time.Duration, error)
}
type NoOpIntervalSettingsRepository struct{}
func NewNoOpIntervalSettingsRepository() IntervalSettingsRepository {
return &NoOpIntervalSettingsRepository{}
}
func (r *NoOpIntervalSettingsRepository) ReadAllIntervals(ctx context.Context, operationId string) (map[string]time.Duration, error) {
return make(map[string]time.Duration), nil
}
func (r *NoOpIntervalSettingsRepository) ReadInterval(ctx context.Context, operationId string, tenantId uuid.UUID) (time.Duration, error) {
return 0, nil
}
func (r *NoOpIntervalSettingsRepository) SetInterval(ctx context.Context, operationId string, tenantId uuid.UUID, d time.Duration) (time.Duration, error) {
return d, nil
}
type intervalSettingsRepository struct {
*sharedRepository
}
func newIntervalSettingsRepository(shared *sharedRepository) IntervalSettingsRepository {
return &intervalSettingsRepository{
sharedRepository: shared,
}
}
func (r *intervalSettingsRepository) ReadAllIntervals(ctx context.Context, operationId string) (map[string]time.Duration, error) {
intervals, err := r.queries.ListIntervalsByOperationId(ctx, r.pool, operationId)
if err != nil {
return nil, err
}
res := make(map[string]time.Duration)
for _, interval := range intervals {
res[interval.TenantID.String()] = time.Duration(interval.IntervalNanoseconds)
}
return res, nil
}
func (r *intervalSettingsRepository) ReadInterval(ctx context.Context, operationId string, tenantId uuid.UUID) (time.Duration, error) {
interval, err := r.queries.ReadInterval(ctx, r.pool, sqlcv1.ReadIntervalParams{
Operationid: operationId,
Tenantid: tenantId,
})
if err != nil {
if errors.Is(err, pgx.ErrNoRows) {
return 0, nil
}
return 0, err
}
res := time.Duration(interval.IntervalNanoseconds)
return res, nil
}
func (r *intervalSettingsRepository) SetInterval(ctx context.Context, operationId string, tenantId uuid.UUID, d time.Duration) (time.Duration, error) {
interval, err := r.queries.UpsertInterval(ctx, r.pool, sqlcv1.UpsertIntervalParams{
Intervalnanoseconds: int64(d),
Operationid: operationId,
Tenantid: tenantId,
})
if err != nil {
return 0, err
}
res := time.Duration(interval.IntervalNanoseconds)
return res, nil
}