Некоторые проверки не удались
CI / test (push) Successful in 2m5s
Docker / Build and publish worker image (push) Failing after 31s
39 строки
761 B
Go
39 строки
761 B
Go
package factories
|
|
|
|
import (
|
|
"rocketgit.ru/rsmon/worker/app/models"
|
|
)
|
|
|
|
// EventFactory provides functionality.
|
|
func EventFactory(monitor *models.Monitor, state, reason string) models.Event {
|
|
event := models.Event{
|
|
Monitor: monitor,
|
|
Checks: monitor.Checks,
|
|
State: state,
|
|
Errors: 10,
|
|
Oks: 0,
|
|
Reason: reason,
|
|
}
|
|
|
|
return event
|
|
}
|
|
|
|
// PersistedEvent provides functionality.
|
|
func PersistedEvent(monitor *models.Monitor, state, reason string) models.Event {
|
|
event := EventFactory(monitor, state, reason)
|
|
|
|
if event.Monitor.ID == 0 {
|
|
err := models.DB().Save(event.Monitor).Error
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
event.MonitorID = event.Monitor.ID
|
|
}
|
|
err := models.DB().Save(&event).Error
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
|
|
return event
|
|
}
|