Skip to content

Commit

Permalink
setup check status to invalid
Browse files Browse the repository at this point in the history
  • Loading branch information
adityathebe committed May 1, 2024
1 parent f87a6e9 commit 97b7562
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
16 changes: 7 additions & 9 deletions api/context/functions.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,13 @@ func (ctx *Context) GetContextualFunctions() map[string]any {
if result, ok := ctx.cache["last_result"]; ok {
return result
}
var status map[string]any

if checkID == "" {
return status
return nil
}

if ctx.DB() == nil {
logger.Errorf("[last_result] db connection not initialized")
return status
return nil
}

type CheckStatus struct {
Expand All @@ -48,10 +46,10 @@ func (ctx *Context) GetContextualFunctions() map[string]any {
Order("time DESC").Limit(1).Scan(&checkStatus).Error
if err != nil {
logger.Warnf("[last_result] failed => %s", err)
return status
return nil
}

status = map[string]any{
lastResult := map[string]any{
"status": checkStatus.Status,
"invalid": checkStatus.Invalid,
"createdAt": checkStatus.CreatedAt,
Expand All @@ -64,15 +62,15 @@ func (ctx *Context) GetContextualFunctions() map[string]any {
if checkStatus.Details != "" {
var details = make(map[string]any)
if err := json.Unmarshal([]byte(checkStatus.Details), &details); err == nil {
status["results"] = details
lastResult["results"] = details
} else {
if ctx.IsTrace() {
ctx.Warnf("[last_result] Failed to unmarshal results: %s", err.Error())
}
}
}
ctx.cache["last_result"] = status
return status
ctx.cache["last_result"] = lastResult
return lastResult
}
}
return funcs
Expand Down
4 changes: 4 additions & 0 deletions pkg/cache/postgres.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ func (c *postgresCache) Add(check pkg.Check, statii ...pkg.CheckStatus) []string
check.Status = "unhealthy"
}

if status.Invalid {
check.Status = "invalid"
}

checkID, err := c.AddCheckFromStatus(check, status)
if err != nil {
logger.Errorf("error persisting check with canary %s: %v", check.CanaryID, err)
Expand Down

0 comments on commit 97b7562

Please sign in to comment.