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:
@@ -9,6 +9,7 @@ import (
|
||||
|
||||
type Status interface {
|
||||
Add(ctx context.Context, status model.Status) error
|
||||
LastNStatuses(ctx context.Context, serviceID uint64, n uint) ([]model.Status, error)
|
||||
}
|
||||
|
||||
type status struct {
|
||||
@@ -24,3 +25,14 @@ func NewStatusRepository() Status {
|
||||
func (s status) Add(ctx context.Context, status model.Status) error {
|
||||
return s.db.WithContext(ctx).Create(&status).Error
|
||||
}
|
||||
|
||||
func (s status) LastNStatuses(ctx context.Context, serviceID uint64, n uint) ([]model.Status, error) {
|
||||
var items = make([]model.Status, 0, n)
|
||||
|
||||
return items, s.db.
|
||||
WithContext(ctx).
|
||||
Limit(int(n)).
|
||||
Order("created_at DESC").
|
||||
Find(&items, "service_id = ?", serviceID).
|
||||
Error
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user