refactor: Switching to a cron system for tasks, restructuring service and status models

Added response time field for Status model, set log level from ENV
This commit is contained in:
2025-10-28 00:51:29 +03:00
parent 1958d9b3d9
commit b33df27b31
11 changed files with 254 additions and 63 deletions

View File

@@ -9,23 +9,29 @@ type HTTPConfig struct {
type ServiceTypeCheckConfig struct {
Version string `json:"version"`
HTTPConfig *HTTPConfig `json:"http_config"`
HTTPConfig *HTTPConfig `json:"httpConfig"`
// MaxFails - max "ping" fails, after with the service marked as unavailable
MaxFails uint8 `json:"maxFails"`
// Interval - interval between "ping" in seconds
Interval uint64 `json:"interval"`
// Timeout - interval after which the task will be canceled
Timeout uint64 `json:"timeout"`
}
type Service struct {
// Unique ID for entity
ID int `gorm:"primary_key;auto_increment" json:"id"`
ID uint64 `gorm:"primary_key;auto_increment" json:"id"`
// Human-readable service name
Name string `gorm:"size:255;not null" json:"name"`
// Human-readable service description
Description string `gorm:"size:255" json:"description"`
PublicDescription string `gorm:"size:255" json:"public_description"`
PublicDescription string `gorm:"size:255" json:"publicDescription"`
Public *bool `gorm:"default:false" json:"public"`
// Host to check, for example 192.168.1.44
// Host to check, for example 192.168.1.44 or https://google.com
Host string `gorm:"size:255;not null" json:"host"`
// Type for check, for now is TCP or HTTP
Type string `gorm:"size:255;not null" json:"type"`
TypeConfig *ServiceTypeCheckConfig `gorm:"serializer:json" json:"type_config"`
// Type for check, for now is TCP or HTTP or something else
Type string `gorm:"size:255;not null" json:"type"`
Config *ServiceTypeCheckConfig `gorm:"serializer:json;column:type_config" json:"typeConfig"`
Statuses []Status `gorm:"foreignkey:ServiceID" json:"statuses"`
}

View File

@@ -15,11 +15,12 @@ const (
)
type Status struct {
ID int `gorm:"primary_key;auto_increment" json:"-"`
ServiceID int `gorm:"one" json:"-"`
Status StatusCode `gorm:"size:255;not null" json:"status"`
Description *string `gorm:"size:255" json:"description"`
CreatedAt time.Time `json:"created_at"`
ID uint64 `gorm:"primary_key;auto_increment" json:"-"`
ServiceID uint64 `json:"-"`
Status StatusCode `gorm:"size:255;not null" json:"status"`
Description *string `gorm:"size:255" json:"description"`
CreatedAt time.Time `json:"createdAt"`
ResponseTime uint64 `json:"responseTime"`
}
func (Status) TableName() string {