-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Expand file tree
/
Copy pathinserter.go
More file actions
53 lines (44 loc) · 1.88 KB
/
Copy pathinserter.go
File metadata and controls
53 lines (44 loc) · 1.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package usage
import (
"context"
"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.
InsertHeartbeatUsageEvent(ctx context.Context, tx database.Store, id string, 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, _ usagetypes.HeartbeatEvent) error {
return nil
}