-
Notifications
You must be signed in to change notification settings - Fork 126
/
event.go
56 lines (43 loc) · 1.17 KB
/
event.go
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
54
55
56
package client
import (
"context"
"encoding/json"
eventcontracts "github.com/hatchet-dev/hatchet/internal/services/ingestor/contracts"
"github.com/hatchet-dev/hatchet/internal/validator"
"github.com/rs/zerolog"
"google.golang.org/grpc"
"google.golang.org/protobuf/types/known/timestamppb"
)
type EventClient interface {
Push(ctx context.Context, eventKey string, payload interface{}) error
}
type eventClientImpl struct {
client eventcontracts.EventsServiceClient
tenantId string
l *zerolog.Logger
v validator.Validator
}
func newEvent(conn *grpc.ClientConn, opts *sharedClientOpts) EventClient {
return &eventClientImpl{
client: eventcontracts.NewEventsServiceClient(conn),
tenantId: opts.tenantId,
l: opts.l,
v: opts.v,
}
}
func (a *eventClientImpl) Push(ctx context.Context, eventKey string, payload interface{}) error {
payloadBytes, err := json.Marshal(payload)
if err != nil {
return err
}
_, err = a.client.Push(ctx, &eventcontracts.PushEventRequest{
TenantId: a.tenantId,
Key: eventKey,
Payload: string(payloadBytes),
EventTimestamp: timestamppb.Now(),
})
if err != nil {
return err
}
return nil
}