Documentation
¶
Index ¶
- Constants
- func GetAllBillableMetricFilters(db *gorm.DB) utils.Result[[]BillableMetricFilter]
- func GetAllBillableMetrics(db *gorm.DB) utils.Result[[]BillableMetric]
- func GetAllChargeFilterValues(db *gorm.DB) utils.Result[[]ChargeFilterValue]
- func GetAllChargeFilters(db *gorm.DB) utils.Result[[]ChargeFilter]
- func GetAllCharges(db *gorm.DB) utils.Result[[]Charge]
- func GetAllSubscriptions(db *gorm.DB) utils.Result[[]Subscription]
- func GetAllWithStreaming[T any](db *gorm.DB, config StreamQueryConfig) utils.Result[[]T]
- func StreamRows[T any](db *gorm.DB, config StreamQueryConfig, callback func(T) error) (int, error)
- type AggregationType
- type ApiStore
- func (store *ApiStore) FetchBillableMetric(organizationID string, code string) utils.Result[*BillableMetric]
- func (store *ApiStore) FetchFlatFilters(planID string, billableMetricCode string) utils.Result[[]*FlatFilter]
- func (store *ApiStore) FetchSubscription(organizationID string, externalID string, timestamp time.Time) utils.Result[*Subscription]
- type BillableMetric
- type BillableMetricFilter
- type CacheStore
- type Cacher
- type Charge
- type ChargeCache
- type ChargeFilter
- type ChargeFilterValue
- type EnrichedEvent
- type Event
- type FailedEvent
- type FlagStore
- type Flagger
- type FlatFilter
- type FlatFilterValues
- type PricingGroupKeys
- type SourceMetadata
- type StreamQueryConfig
- type Subscription
Constants ¶
const ( AggregationTypeCount = iota AggregationTypeSum AggregationTypeMax AggregationTypeUniqueCount AggregationTypeWeightedSum AggregationTypeLatest AggregationTypeCustom )
const CACHE_KEY_VERSION = "1"
const EXPIRATION_TIME = 10 * time.Second
const HTTP_RUBY string = "http_ruby"
const SUBSCRIPTION_BUCKET_DURATION int64 = 10
const TARGET_WALLET_CODE string = "target_wallet_code"
Variables ¶
This section is empty.
Functions ¶
func GetAllBillableMetricFilters ¶
func GetAllBillableMetricFilters(db *gorm.DB) utils.Result[[]BillableMetricFilter]
func GetAllBillableMetrics ¶
func GetAllBillableMetrics(db *gorm.DB) utils.Result[[]BillableMetric]
func GetAllChargeFilterValues ¶
func GetAllChargeFilterValues(db *gorm.DB) utils.Result[[]ChargeFilterValue]
func GetAllChargeFilters ¶
func GetAllChargeFilters(db *gorm.DB) utils.Result[[]ChargeFilter]
func GetAllSubscriptions ¶
func GetAllSubscriptions(db *gorm.DB) utils.Result[[]Subscription]
We want to get terminated subscriptions to permit grace period events backfill So we select all non terminated subscriptions and subs terminated less that one month ago
func GetAllWithStreaming ¶
func StreamRows ¶
Types ¶
type AggregationType ¶
type AggregationType int
func (AggregationType) String ¶
func (t AggregationType) String() string
type ApiStore ¶
type ApiStore struct {
// contains filtered or unexported fields
}
func NewApiStore ¶
func (*ApiStore) FetchBillableMetric ¶
func (*ApiStore) FetchFlatFilters ¶
func (*ApiStore) FetchSubscription ¶
type BillableMetric ¶
type BillableMetric struct {
ID string `gorm:"primaryKey;->" json:"id"`
OrganizationID string `gorm:"->" json:"organization_id"`
Code string `gorm:"->" json:"code"`
AggregationType AggregationType `gorm:"->" json:"aggregation_type"`
FieldName string `gorm:"->" json:"field_name"`
Expression string `gorm:"->" json:"expression"`
CreatedAt utils.NullTime `gorm:"->" json:"created_at"`
UpdatedAt utils.NullTime `gorm:"->" json:"updated_at"`
DeletedAt utils.NullTime `gorm:"index;->" json:"deleted_at"`
}
type BillableMetricFilter ¶
type BillableMetricFilter struct {
ID string `gorm:"primaryKey;->" json:"id"`
OrganizationID string `gorm:"->" json:"organization_id"`
BillableMetricID string `gorm:"->" json:"billable_metric_id"`
Key string `gorm:"->" json:"key"`
Values utils.StringArray `gorm:"type:text[];->" json:"values"`
CreatedAt utils.NullTime `gorm:"->" json:"created_at"`
UpdatedAt utils.NullTime `gorm:"->" json:"updated_at"`
DeletedAt utils.NullTime `gorm:"->" json:"deleted_at"`
}
type CacheStore ¶
type CacheStore struct {
// contains filtered or unexported fields
}
func NewCacheStore ¶
func NewCacheStore(ctx context.Context, redis *redis.RedisDB) *CacheStore
func (*CacheStore) Close ¶
func (store *CacheStore) Close() error
type Charge ¶
type Charge struct {
ID string `gorm:"primaryKey;->" json:"id"`
OrganizationID string `gorm:"->" json:"organization_id"`
PlanID string `gorm:"->" json:"plan_id"`
BillableMetricID string `gorm:"->" json:"billable_metric_id"`
PayInAdvance bool `gorm:"->" json:"pay_in_advance"`
AcceptsTargetWallet bool `gorm:"->" json:"accepts_target_wallet"`
PricingGroupKeys utils.StringArray `gorm:"type:jsonb;->" json:"properties.pricing_group_keys"`
CreatedAt utils.NullTime `gorm:"->" json:"created_at"`
UpdatedAt utils.NullTime `gorm:"->" json:"updated_at"`
DeletedAt utils.NullTime `gorm:"->" json:"deleted_at"`
}
type ChargeCache ¶
type ChargeCache struct {
CacheStore Cacher
}
func NewChargeCache ¶
func NewChargeCache(cacheStore *Cacher) *ChargeCache
func (*ChargeCache) Expire ¶
func (cache *ChargeCache) Expire(ff *FlatFilter, subID string) utils.Result[bool]
type ChargeFilter ¶
type ChargeFilter struct {
ID string `gorm:"primaryKey;->" json:"id"`
OrganizationID string `gorm:"->" json:"organization_id"`
ChargeID string `gorm:"->" json:"charge_id"`
PricingGroupKeys utils.StringArray `gorm:"type:jsonb;->" json:"properties.pricing_group_keys"`
CreatedAt utils.NullTime `gorm:"->" json:"created_at"`
UpdatedAt utils.NullTime `gorm:"->" json:"updated_at"`
DeletedAt utils.NullTime `gorm:"->" json:"deleted_at"`
}
type ChargeFilterValue ¶
type ChargeFilterValue struct {
ID string `gorm:"primaryKey;->" json:"id"`
OrganizationID string `gorm:"->" json:"organization_id"`
ChargeFilterID string `gorm:"->" json:"charge_filter_id"`
BillableMetricFilterID string `gorm:"->" json:"billable_metric_filter_id"`
Values utils.StringArray `gorm:"type:text[];->" json:"values"`
CreatedAt utils.NullTime `gorm:"->" json:"created_at"`
UpdatedAt utils.NullTime `gorm:"->" json:"updated_at"`
DeletedAt utils.NullTime `gorm:"->" json:"deleted_at"`
}
type EnrichedEvent ¶
type EnrichedEvent struct {
InitialEvent *Event `json:"-"`
BillableMetric *BillableMetric `json:"-"`
Subscription *Subscription `json:"-"`
FlatFilter *FlatFilter `json:"-"`
OrganizationID string `json:"organization_id"`
ExternalSubscriptionID string `json:"external_subscription_id"`
SubscriptionID string `json:"subscription_id"`
PlanID string `json:"plan_id"`
TransactionID string `json:"transaction_id"`
Code string `json:"code"`
AggregationType string `json:"aggregation_type"`
Properties map[string]any `json:"properties"`
PreciseTotalAmountCents string `json:"precise_total_amount_cents"`
Source string `json:"source,omitempty"`
Value *string `json:"value"`
Timestamp float64 `json:"timestamp"`
TimestampStr string `json:"-"`
Time time.Time `json:"-"`
ChargeID *string `json:"charge_id"`
ChargeUpdatedAt *time.Time `json:"charge_updated_at"`
ChargeFilterID *string `json:"charge_filter_id"`
ChargeFilterUpdatedAt *time.Time `json:"charge_filter_updated_at"`
GroupedBy map[string]string `json:"grouped_by"`
TargetWalletCode *string `json:"target_wallet_code"`
}
type Event ¶
type Event struct {
OrganizationID string `json:"organization_id"`
ExternalSubscriptionID string `json:"external_subscription_id"`
TransactionID string `json:"transaction_id"`
Code string `json:"code"`
Properties map[string]any `json:"properties"`
PreciseTotalAmountCents string `json:"precise_total_amount_cents"`
Source string `json:"source,omitempty"`
Timestamp any `json:"timestamp"`
SourceMetadata *SourceMetadata `json:"source_metadata"`
IngestedAt utils.CustomTime `json:"ingested_at"`
}
func (*Event) IsReprocess ¶
func (*Event) NotAPIPostProcessed ¶
func (*Event) ToEnrichedEvent ¶
func (ev *Event) ToEnrichedEvent() utils.Result[*EnrichedEvent]
type FailedEvent ¶
type FlagStore ¶
type FlagStore struct {
// contains filtered or unexported fields
}
func NewFlagStore ¶
func (*FlagStore) Flag ¶
Flag adds a subscription to the sorted set for delayed refresh. The member key includes a time bucket (value|bucket) so that events within the same SUBSCRIPTION_BUCKET_DURATION window share a member — ZADD overwrites the score to the latest event, waiting after the last event in that window. Once the window elapses, new events create a new member, ensuring the previous one ages out and gets picked up by the consumer (no starvation).
type FlatFilter ¶
type FlatFilter struct {
OrganizationID string `gorm:"->"`
BillableMetricCode string `gorm:"->"`
PlanID string `gorm:"->"`
ChargeID string `gorm:"->"`
ChargeUpdatedAt time.Time `gorm:"->"`
ChargeFilterID *string `gorm:"->"`
ChargeFilterUpdatedAt *time.Time `gorm:"->"`
Filters *FlatFilterValues `gorm:"type:jsonb"`
PricingGroupKeys PricingGroupKeys `gorm:"type:jsonb"`
PayInAdvance bool `gorm:"type:boolean"`
AcceptsTargetWallet bool `gorm:"type:boolean"`
}
func MatchingFilter ¶
func MatchingFilter(filters []FlatFilter, event *EnrichedEvent) *FlatFilter
func (*FlatFilter) HasFilters ¶
func (ff *FlatFilter) HasFilters() bool
func (*FlatFilter) IsMatchingEvent ¶
func (ff *FlatFilter) IsMatchingEvent(event *EnrichedEvent) utils.Result[bool]
func (*FlatFilter) ToDefaultFilter ¶
func (ff *FlatFilter) ToDefaultFilter() *FlatFilter
type FlatFilterValues ¶
func (*FlatFilterValues) Keys ¶
func (ffv *FlatFilterValues) Keys() []string
func (*FlatFilterValues) Scan ¶
func (fm *FlatFilterValues) Scan(value any) error
Implements the sql.Scanner interface to convert JSONB into FlatFilterValues
type PricingGroupKeys ¶
type PricingGroupKeys []string
func (*PricingGroupKeys) Scan ¶
func (fm *PricingGroupKeys) Scan(value any) error
Implements the sql.Scanner interface to convert JSONB into FlatFilterValues
type SourceMetadata ¶
type StreamQueryConfig ¶
type Subscription ¶
type Subscription struct {
ID string `gorm:"primaryKey;->" json:"id"`
OrganizationID *string `gorm:"->" json:"organization_id"`
ExternalID string `gorm:"->" json:"external_id"`
PlanID string `gorm:"->" json:"plan_id"`
CreatedAt utils.NullTime `gorm:"->" json:"created_at"`
UpdatedAt utils.NullTime `gorm:"->" json:"updated_at"`
StartedAt utils.NullTime `gorm:"->" json:"started_at"`
TerminatedAt utils.NullTime `gorm:"->" json:"terminated_at"`
}