generated from fun-stack/example
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a898c80
commit c06ec1a
Showing
2 changed files
with
40 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package main | ||
|
||
import ( | ||
"net/http" | ||
"time" | ||
"fmt" | ||
|
||
"github.com/pkg/errors" | ||
) | ||
|
||
const alertAfterMinutes = 5 | ||
|
||
|
||
func (app app) healthHandler() func(http.ResponseWriter, *http.Request, loginParams) error { | ||
return func(w http.ResponseWriter, r *http.Request, p loginParams) error { | ||
|
||
w.Header().Set("Content-Type", "text/plain; charset=utf-8") | ||
|
||
lastSampleTime, err := app.ndb.selectLastCrawlTime() | ||
if err != nil { | ||
// Return a 500 error | ||
return errors.Wrap(err, "getting last crawl time") | ||
} | ||
|
||
if time.Now().Unix()-int64(lastSampleTime) > alertAfterMinutes*60 { | ||
return fmt.Errorf("last successful crawl of %d is more than %d minutes ago", lastSampleTime, alertAfterMinutes) | ||
} | ||
|
||
// write "ok" | ||
_, err = w.Write([]byte("ok")) | ||
if err != nil { | ||
return errors.Wrap(err, "writing response") | ||
} | ||
|
||
return nil | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters