Skip to content

Commit

Permalink
feat: playbook as notification recipient
Browse files Browse the repository at this point in the history
  • Loading branch information
adityathebe committed Dec 16, 2024
1 parent a2cfd9e commit 1585e49
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 7 deletions.
6 changes: 5 additions & 1 deletion models/notifications.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ type Notification struct {
Title string `json:"title,omitempty"`
Template string `json:"template,omitempty"`
Filter string `json:"filter,omitempty"`
PlaybookID *uuid.UUID `json:"playbook_id,omitempty"`
PersonID *uuid.UUID `json:"person_id,omitempty"`
TeamID *uuid.UUID `json:"team_id,omitempty"`
Properties types.JSONStringMap `json:"properties,omitempty"`
Expand Down Expand Up @@ -50,7 +51,7 @@ func (n Notification) PK() string {
}

func (n *Notification) HasRecipients() bool {
return n.TeamID != nil || n.PersonID != nil || len(n.CustomServices) != 0
return n.TeamID != nil || n.PersonID != nil || len(n.CustomServices) != 0 || n.PlaybookID != nil
}

func (n Notification) AsMap(removeFields ...string) map[string]any {
Expand Down Expand Up @@ -105,6 +106,9 @@ type NotificationSendHistory struct {
// ID of the person this notification is for.
PersonID *uuid.UUID `json:"person_id"`

// The run created by this notification
PlaybookRunID *uuid.UUID `json:"playbook_run_id"`

timeStart time.Time
}

Expand Down
8 changes: 8 additions & 0 deletions models/playbooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,14 @@ type Playbook struct {
DeletedAt *time.Time `json:"deleted_at,omitempty" time_format:"postgres_timestamp"`
}

func (p *Playbook) NamespacedName() string {
if p.Namespace != "" {
return fmt.Sprintf("%s/%s", p.Namespace, p.Name)
}

return p.Name
}

func (p *Playbook) LoggerName() string {
return "playbook." + p.Name
}
Expand Down
22 changes: 16 additions & 6 deletions schema/notifications.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ table "notifications" {
type = jsonb
comment = "Shoutrrr properties used when sending email to the person receipient."
}
column "playbook_id" {
null = true
type = uuid
comment = "playbook to trigger"
}
column "person_id" {
null = true
type = uuid
Expand Down Expand Up @@ -145,17 +150,17 @@ table "notification_send_history" {
type = text
}
column "not_before" {
null = true
type = timestamptz
null = true
type = timestamptz
}
column "retries" {
null = true
type = integer
null = true
type = integer
comment = "number of retries of pending notifications"
}
column "payload" {
null = true
type = jsonb
null = true
type = jsonb
comment = "holds in original event properties for delayed/pending notifications"
}
column "count" {
Expand All @@ -182,6 +187,11 @@ table "notification_send_history" {
null = true
type = uuid
}
column "playbook_run_id" {
null = true
type = uuid
comment = "playbook run created by this notification dispatch"
}
column "error" {
null = true
type = text
Expand Down

0 comments on commit 1585e49

Please sign in to comment.