diff --git a/models/notifications.go b/models/notifications.go index 5c14f6ef..80b4b972 100644 --- a/models/notifications.go +++ b/models/notifications.go @@ -55,6 +55,7 @@ const ( NotificationStatusError = "error" NotificationStatusSent = "sent" NotificationStatusSending = "sending" + NotificationStatusPending = "pending" // delayed NotificationStatusSilenced = "silenced" NotificationStatusRepeatInterval = "repeat-interval" ) @@ -68,13 +69,21 @@ type NotificationSendHistory struct { CreatedAt time.Time `json:"created_at" time_format:"postgres_timestamp"` Status string `json:"status,omitempty"` + // payload holds in original event properties for delayed/pending notifications + Payload types.JSONStringMap `json:"payload,omitempty"` + + NotBefore *time.Time `json:"notBefore,omitempty"` + + // number of retries of pending notifications + Retries int `json:"retries,omitempty" gorm:"default:null"` + // Notifications that were silenced or blocked by repeat intervals // use this counter. Count int `json:"count"` // Notifications that were silenced or blocked by repeat intervals // use this as the first observed timestamp. - FirstObserved time.Time `json:"first_observed"` + FirstObserved time.Time `json:"first_observed" gorm:"<-:false"` // Name of the original event that caused this notification SourceEvent string `json:"source_event"` @@ -103,6 +112,11 @@ func NewNotificationSendHistory(notificationID uuid.UUID) *NotificationSendHisto } } +func (t *NotificationSendHistory) WithStartTime(s time.Time) *NotificationSendHistory { + t.timeStart = s + return t +} + func (t *NotificationSendHistory) Sending() *NotificationSendHistory { t.Status = NotificationStatusSending return t diff --git a/schema/notifications.hcl b/schema/notifications.hcl index 92688b8d..adadf82e 100644 --- a/schema/notifications.hcl +++ b/schema/notifications.hcl @@ -139,6 +139,20 @@ table "notification_send_history" { null = true type = text } + column "not_before" { + null = true + type = timestamptz + } + column "retries" { + null = true + type = integer + comment = "number of retries of pending notifications" + } + column "payload" { + null = true + type = jsonb + comment = "holds in original event properties for delayed/pending notifications" + } column "count" { null = false default = 1