Files
worker/app/models/message.go
Gleb Tv 2c7a0236da feat: publish standalone worker
Separate worker packaging and service lifecycle from the control plane.
2026-07-13 17:55:14 +03:00

49 строки
1.2 KiB
Go

package models
import (
"time"
"gorm.io/gorm"
"rsgit.ru/rsmon/rsmon/app/models/concerns"
)
// Message info about performed notification
type Message struct {
concerns.Model
NotificationID int64 `json:"notification_id"`
Notification *Notification `json:"notification,omitempty"`
ContactID int64 `gorm:"index;type:bigint REFERENCES contacts(id)" json:"contact_id"`
Contact *Contact `json:"contact,omitempty"`
// Events are for up/down messages
Events []Event `json:"events" gorm:"many2many:event_messages;"`
// Checks are for expires messages
CheckID *int64 `gorm:"index;type:bigint REFERENCES checks(id)" json:"check_id"`
Check *Check `json:"check,omitempty"`
Kind string `json:"kind"`
State string `json:"state"`
Error *string `json:"error"`
Response *string `json:"response"`
Tries int `json:"-"`
CreatedAt time.Time `json:"created_at"`
SentAt time.Time `json:"sent_at"`
}
// MessageScope provides functionality.
func MessageScope(q *gorm.DB) *gorm.DB {
return q.
Preload("Events").
Preload("Events.Checks").
Preload("Events.Monitor").
Preload("Notification").
Preload("Contact").
Preload("Check").
Preload("Check.Monitor")
}