Skip to content

Commit

Permalink
feat: notification wait for in send history (#1194)
Browse files Browse the repository at this point in the history
* feat: notification wait for in send history

* feat: save original event payload in notification send history table

* add `not_before` & retries count
  • Loading branch information
adityathebe authored Nov 13, 2024
1 parent ef63f28 commit 6d646ff
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
16 changes: 15 additions & 1 deletion models/notifications.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ const (
NotificationStatusError = "error"
NotificationStatusSent = "sent"
NotificationStatusSending = "sending"
NotificationStatusPending = "pending" // delayed
NotificationStatusSilenced = "silenced"
NotificationStatusRepeatInterval = "repeat-interval"
)
Expand All @@ -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"`
Expand Down Expand Up @@ -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
Expand Down
14 changes: 14 additions & 0 deletions schema/notifications.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 6d646ff

Please sign in to comment.