-
Notifications
You must be signed in to change notification settings - Fork 145
/
event.go
45 lines (35 loc) · 1.15 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
package transformers
import (
"fmt"
"github.com/hatchet-dev/hatchet/api/v1/server/oas/gen"
"github.com/hatchet-dev/hatchet/internal/repository/prisma/db"
"github.com/hatchet-dev/hatchet/internal/repository/prisma/dbsqlc"
"github.com/jackc/pgx/v5/pgtype"
)
func ToEvent(event *db.EventModel) *gen.Event {
res := &gen.Event{
Metadata: *toAPIMetadata(event.ID, event.CreatedAt, event.UpdatedAt),
Key: event.Key,
TenantId: event.TenantID,
}
return res
}
func ToEventFromSQLC(eventRow *dbsqlc.ListEventsRow) *gen.Event {
event := eventRow.Event
res := &gen.Event{
Metadata: *toAPIMetadata(pgUUIDToStr(event.ID), event.CreatedAt.Time, event.UpdatedAt.Time),
Key: event.Key,
TenantId: pgUUIDToStr(event.TenantId),
}
res.WorkflowRunSummary = &gen.EventWorkflowRunSummary{
Failed: &eventRow.Failedruns,
Running: &eventRow.Runningruns,
Succeeded: &eventRow.Succeededruns,
Pending: &eventRow.Pendingruns,
Queued: &eventRow.Queuedruns,
}
return res
}
func pgUUIDToStr(uuid pgtype.UUID) string {
return fmt.Sprintf("%x-%x-%x-%x-%x", uuid.Bytes[0:4], uuid.Bytes[4:6], uuid.Bytes[6:8], uuid.Bytes[8:10], uuid.Bytes[10:16])
}