-
Notifications
You must be signed in to change notification settings - Fork 1
/
event_queue.go
64 lines (54 loc) · 1.69 KB
/
event_queue.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
57
58
59
60
61
62
63
64
package models
import (
"time"
"github.com/flanksource/duty/types"
"github.com/flanksource/postq"
"github.com/google/uuid"
)
type Event struct {
ID uuid.UUID `gorm:"default:generate_ulid()"`
Name string `json:"name"`
CreatedAt time.Time `json:"created_at"`
Properties types.JSONStringMap `json:"properties"`
Error *string `json:"error,omitempty"`
Attempts int `json:"attempts"`
LastAttempt *time.Time `json:"last_attempt"`
Priority int `json:"priority"`
}
func (t Event) ToPostQEvent() postq.Event {
return postq.Event{
ID: t.ID,
Name: t.Name,
Error: t.Error,
Attempts: t.Attempts,
LastAttempt: t.LastAttempt,
Properties: t.Properties,
CreatedAt: t.CreatedAt,
}
}
// We are using the term `Event` as it represents an event in the
// event_queue table, but the table is named event_queue
// to signify it's usage as a queue
func (Event) TableName() string {
return "event_queue"
}
type Events []Event
func (events Events) ToPostQEvents() postq.Events {
var output []postq.Event
for _, event := range events {
output = append(output, event.ToPostQEvent())
}
return output
}
type EventQueueSummary struct {
Name string `json:"name"`
Pending int64 `json:"pending"`
Failed int64 `json:"failed"`
AvgAttempts int64 `json:"average_attempts"`
FirstFailure *time.Time `json:"first_failure,omitempty"`
LastFailure *time.Time `json:"last_failure,omitempty"`
MostCommonErr string `json:"most_common_error,omitempty"`
}
func (t *EventQueueSummary) TableName() string {
return "event_queue_summary"
}