Ctrl K
ComunidadGuías…

coderd/usage/inserter.go

Rama main · réplica de lectura del repositorio original.

Archivo original ↗Preguntar a KiBot
package usage

import (
	"context"
	"time"

	"github.com/coder/coder/v2/coderd/database"
	"github.com/coder/coder/v2/coderd/usage/usagetypes"
)

// Inserter accepts usage events generated by the product.
type Inserter interface {
	// InsertDiscreteUsageEvent writes a discrete usage event to the database
	// within the given transaction.
	// The caller context must be authorized to create usage events in the
	// database.
	InsertDiscreteUsageEvent(ctx context.Context, tx database.Store, event usagetypes.DiscreteEvent) error

	// InsertHeartbeatUsageEvent writes a heartbeat usage event to the database
	// within the given transaction.
	//
	// The caller context must be authorized to create usage events in the database.
	//
	// The `id` should be a stable identifier for the event. Heartbeat events may be
	// emitted by multiple replicas of the same daemon, so the same logical event
	// may be submitted multiple times concurrently. For this reason the identifier
	// must be deterministic and stateless, allowing duplicate submissions to be
	// safely ignored.
	//
	// Inserts with the same `id` must be idempotent. The database enforces this by
	// ignoring duplicate records.
	//
	// Generators that backfill historical buckets pass the bucket start as
	// `createdAt` rather than the insertion time. `createdAt` must be
	// non-zero; implementations reject the zero time rather than storing it.
	InsertHeartbeatUsageEvent(ctx context.Context, tx database.Store, id string, createdAt time.Time, event usagetypes.HeartbeatEvent) error
}

// AGPLInserter is a no-op implementation of Inserter.
type AGPLInserter struct{}

var _ Inserter = AGPLInserter{}

func NewAGPLInserter() Inserter {
	return AGPLInserter{}
}

// InsertDiscreteUsageEvent is a no-op implementation of
// InsertDiscreteUsageEvent.
func (AGPLInserter) InsertDiscreteUsageEvent(_ context.Context, _ database.Store, _ usagetypes.DiscreteEvent) error {
	return nil
}

// InsertHeartbeatUsageEvent is a no-op implementation of
// InsertHeartbeatUsageEvent.
func (AGPLInserter) InsertHeartbeatUsageEvent(_ context.Context, _ database.Store, _ string, _ time.Time, _ usagetypes.HeartbeatEvent) error {
	return nil
}