feat: publish standalone worker
Separate worker packaging and service lifecycle from the control plane.
Этот коммит содержится в:
53
spec/factories/notifications.go
Обычный файл
53
spec/factories/notifications.go
Обычный файл
@@ -0,0 +1,53 @@
|
||||
package factories
|
||||
|
||||
import (
|
||||
"github.com/icrowley/fake"
|
||||
|
||||
"rsgit.ru/rsmon/rsmon/app/models"
|
||||
)
|
||||
|
||||
// NotificationFactory provides functionality.
|
||||
func NotificationFactory(account *models.Account, contactIDs, groupIDs []int64, alertDelay int64, notifyRestore bool) models.Notification {
|
||||
BeforeExpiration := int64(3600)
|
||||
notification := models.Notification{
|
||||
Name: fake.Company(),
|
||||
ContactIDs: contactIDs,
|
||||
GroupIDs: groupIDs,
|
||||
AlertDelay: &alertDelay,
|
||||
NotifyDown: true,
|
||||
NotifyRestore: notifyRestore,
|
||||
BeforeExpiration: &BeforeExpiration,
|
||||
}
|
||||
if account == nil {
|
||||
c := AccountFactory()
|
||||
account = &c
|
||||
}
|
||||
notification.Account = account
|
||||
notification.AccountID = account.ID
|
||||
|
||||
return notification
|
||||
}
|
||||
|
||||
// PersistedNotification provides functionality.
|
||||
func PersistedNotification(account *models.Account, contactIDs, groupIDs []int64, alertDelay int64, notifyRestore bool) models.Notification { //nolint:lll
|
||||
notification := NotificationFactory(account, contactIDs, groupIDs, alertDelay, notifyRestore)
|
||||
|
||||
if notification.Account.ID == 0 {
|
||||
err := models.DB().Save(¬ification.Account).Error
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
notification.AccountID = notification.Account.ID
|
||||
}
|
||||
err := models.DB().Save(¬ification).Error
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
err = notification.PersistRelations()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
return notification
|
||||
}
|
||||
Ссылка в новой задаче
Block a user