credit

package
v1.0.0-beta.160 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 23, 2024 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SortedPeriodsFromDedupedTimes

func SortedPeriodsFromDedupedTimes(ts []time.Time) []recurrence.Period

Returns a list of non-overlapping periods between the sorted times.

Types

type BalanceConnector

type BalanceConnector interface {
	GetBalanceOfOwner(ctx context.Context, owner grant.NamespacedOwner, at time.Time) (*balance.Snapshot, error)
	GetBalanceHistoryOfOwner(ctx context.Context, owner grant.NamespacedOwner, params BalanceHistoryParams) (engine.GrantBurnDownHistory, error)
	ResetUsageForOwner(ctx context.Context, owner grant.NamespacedOwner, params ResetUsageForOwnerParams) (balanceAfterReset *balance.Snapshot, err error)
}

Generic connector for balance related operations.

type BalanceHistoryParams

type BalanceHistoryParams struct {
	From time.Time
	To   time.Time
}

type CreateGrantInput

type CreateGrantInput struct {
	Amount           float64
	Priority         uint8
	EffectiveAt      time.Time
	Expiration       grant.ExpirationPeriod
	Metadata         map[string]string
	ResetMaxRollover float64
	ResetMinRollover float64
	Recurrence       *recurrence.Recurrence
}

type CreditConnector

type CreditConnector interface {
	BalanceConnector
	GrantConnector
}

func NewCreditConnector

func NewCreditConnector(
	grantRepo grant.Repo,
	balanceSnapshotRepo balance.SnapshotRepo,
	ownerConnector grant.OwnerConnector,
	streamingConnector streaming.Connector,
	logger *slog.Logger,
	granularity time.Duration,
	publisher eventbus.Publisher,
) CreditConnector

type GrantConnector

type GrantConnector interface {
	CreateGrant(ctx context.Context, owner grant.NamespacedOwner, grant CreateGrantInput) (*grant.Grant, error)
	VoidGrant(ctx context.Context, grantID models.NamespacedID) error
}

type GrantNotFoundError

type GrantNotFoundError struct {
	GrantID string
}

func (*GrantNotFoundError) Error

func (e *GrantNotFoundError) Error() string

type ResetUsageForOwnerParams

type ResetUsageForOwnerParams struct {
	At              time.Time
	RetainAnchor    bool
	PreserveOverage bool
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL