-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: make event queue related structs public
- Loading branch information
1 parent
aa19bf6
commit 8b0b5df
Showing
2 changed files
with
81 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
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" | ||
} | ||
|
||
type PushQueueSummary struct { | ||
Table string `json:"table"` | ||
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 *PushQueueSummary) TableName() string { | ||
return "push_queue_summary" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters