-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from hellofresh/feature/checker-mongo
Feature/checker mongo
- Loading branch information
Showing
6 changed files
with
73 additions
and
35 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 |
---|---|---|
|
@@ -6,6 +6,7 @@ | |
* PostgreSQL | ||
* Redis | ||
* HTTP | ||
* MongoDB | ||
|
||
## Usage | ||
|
||
|
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
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 mongo | ||
|
||
import "gopkg.in/mgo.v2" | ||
|
||
// Config is the MongoDB checker configuration settings container. | ||
type Config struct { | ||
// DSN is the MongoDB instance connection DSN. Required. | ||
DSN string | ||
// LogFunc is the callback function for errors logging during check. | ||
// If not set logging is skipped. | ||
LogFunc func(err error, details string, extra ...interface{}) | ||
} | ||
|
||
// New creates new MongoDB health check that verifies the following: | ||
// - connection establishing | ||
// - doing the ping command | ||
func New(config Config) func() error { | ||
if config.LogFunc == nil { | ||
config.LogFunc = func(err error, details string, extra ...interface{}) {} | ||
} | ||
|
||
return func() error { | ||
session, err := mgo.Dial(config.DSN) | ||
if err != nil { | ||
config.LogFunc(err, "MongoDB health check failed during connect") | ||
return err | ||
} | ||
defer session.Close() | ||
|
||
err = session.Ping() | ||
if err != nil { | ||
config.LogFunc(err, "MongoDB health check failed during ping") | ||
return err | ||
} | ||
|
||
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
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
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