Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix status check #1519

Merged
merged 2 commits into from
Dec 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cmd/offline.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ var GoOffline = &cobra.Command{
defer os.RemoveAll(databaseDir)

db.ConnectionString = "embedded://" + databaseDir
if err := db.Init(); err != nil {
if err := db.Connect(); err != nil {
logger.Fatalf("Failed to run in embedded mode: %+v", err)
}
if err := db.PostgresServer.Stop(); err != nil {
Expand Down
4 changes: 4 additions & 0 deletions pkg/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,10 @@ func (c Check) ToString() string {
return fmt.Sprintf("%s-%s-%s", c.Name, c.Type, c.Description)
}

func (c Check) String() string {
return fmt.Sprintf("%s/%s type=%s", c.Namespace, c.Name, c.Type)
}

func (c Check) GetDescription() string {
return c.Description
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/cache/postgres.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func (c *postgresCache) AddCheckStatus(check pkg.Check, status pkg.CheckStatus)
}

if len(checks) == 0 || checks[0].ID == uuid.Nil {
logger.Debugf("check not found")
logger.Tracef("%s check not found, skipping status insert", check)
return
}
_, err = c.Exec(gocontext.TODO(), `INSERT INTO check_statuses(
Expand Down
5 changes: 4 additions & 1 deletion pkg/db/canary.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,11 @@ func GetTransformedCheckIDs(ctx context.Context, canaryID string, excludeTypes .
}

func LatestCheckStatus(ctx context.Context, checkID string) (*models.CheckStatus, error) {
if uuid.Nil.String() == checkID {
return nil, nil
}
var status models.CheckStatus
if err := ctx.DB().Select("time, created_at, status").Where("check_id = ?", checkID).Order("created_at DESC").Find(&status).Error; err != nil {
if err := ctx.DB().Limit(1).Select("time, created_at, status").Where("check_id = ?", checkID).Order("created_at DESC").Find(&status).Error; err != nil {
if errors.Is(err, gorm.ErrRecordNotFound) {
return nil, nil
}
Expand Down
8 changes: 6 additions & 2 deletions pkg/db/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func embeddedDB() error {
return nil
}

func Init() error {
func Connect() error {
if ConnectionString == "" || ConnectionString == "DB_URL" {
logger.Warnf("No db connection string specified")
return nil
Expand All @@ -101,7 +101,11 @@ func Init() error {
}

Gorm, err = duty.NewGorm(ConnectionString, duty.DefaultGormConfig())
if err != nil {
return err
}

func Init() error {
if err := Connect(); err != nil {
return err
}

Expand Down
Loading