File tree Expand file tree Collapse file tree 2 files changed +24
-16
lines changed Expand file tree Collapse file tree 2 files changed +24
-16
lines changed Original file line number Diff line number Diff line change @@ -18,6 +18,16 @@ import (
1818 "gorm.io/gorm"
1919)
2020
21+ func init () {
22+
23+ if pgUri , exists := os .LookupEnv ("POSTGRES_URI" ); exists && pgUri != "" {
24+ fmt .Println ("WARN: Using POSTGRES_URI environment variable to override DATABASE_URL" )
25+ os .Setenv ("DATABASE_URL" , pgUri )
26+ fmt .Println ("Using DATABASE_URL:" , os .Getenv ("DATABASE_URL" ))
27+ }
28+
29+ }
30+
2131var (
2232 defaultPort int64 = 8080
2333 slackSigningSecretConfigKey = "slackSigningSecret"
3545 slackCallbackURLConfigKey : os .Getenv ("SLACK_CALLBACK_URL" ),
3646 legacyCryptoKeyConfigKey : os .Getenv ("CRYPTO_KEY" ),
3747 appURLConfigKey : os .Getenv ("APP_URL" ),
38- databaseURL : os .Getenv ("DATABASE_URL" ),
48+ databaseURL : os .Getenv ("DATABASE_URL" ), // if POSTGRES_URI is set, it will override DATABASE_URL
3949 }
4050)
4151
Original file line number Diff line number Diff line change @@ -5,28 +5,26 @@ import (
55 "os"
66
77 "github.com/gin-gonic/gin"
8+ "go.uber.org/zap"
89)
910
1011func (ctl * PublicController ) HandleHealth (c * gin.Context ) {
1112 version , ok := os .LookupEnv ("NF_DEPLOYMENT_SHA" )
1213 if ! ok {
1314 version = "dev"
1415 }
16+ db , err := ctl .db .DB ()
17+ if err != nil {
18+ ctl .logger .Error ("error retrieving database connection" , zap .Error (err ))
19+ c .AbortWithStatusJSON (http .StatusServiceUnavailable , gin.H {"status" : "DOWN" , "sha" : version })
20+ return
21+ }
1522
16- // Neon removed their free tier. It now costs me money to keep the database up, so let it sleep to save costs.
17-
18- // db, err := ctl.db.DB()
19- // if err != nil {
20- // log.Error(err)
21- // c.AbortWithStatusJSON(http.StatusServiceUnavailable, gin.H{"status": "DOWN", "sha": version})
22- // return
23- // }
24-
25- // err = db.PingContext(c.Request.Context())
26- // if err != nil {
27- // log.Error(err)
28- // c.AbortWithStatusJSON(http.StatusServiceUnavailable, gin.H{"status": "DOWN", "sha": version})
29- // return
30- // }
23+ err = db .PingContext (c .Request .Context ())
24+ if err != nil {
25+ ctl .logger .Error ("error pinging database" , zap .Error (err ))
26+ c .AbortWithStatusJSON (http .StatusServiceUnavailable , gin.H {"status" : "DOWN" , "sha" : version })
27+ return
28+ }
3129 c .JSON (http .StatusOK , gin.H {"status" : "UP" , "sha" : version })
3230}
You can’t perform that action at this time.
0 commit comments