Skip to content

Commit

Permalink
Merge pull request #606 from 0xPolygonID/PID-1698-add-health-check-en…
Browse files Browse the repository at this point in the history
…dpoint-to-pending-publisher-and-notifications-components

chore: add health check endpoint
  • Loading branch information
martinsaporiti authored Jan 29, 2024
2 parents e7ab6e3 + 137a577 commit 696fdb9
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 2 deletions.
19 changes: 17 additions & 2 deletions cmd/notifications/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"fmt"
"math/big"
"net/http"
"os"
"os/signal"
"syscall"
Expand All @@ -28,7 +29,7 @@ import (
"github.com/polygonid/sh-id-platform/pkg/blockchain/eth"
"github.com/polygonid/sh-id-platform/pkg/cache"
"github.com/polygonid/sh-id-platform/pkg/credentials/revocation_status"
"github.com/polygonid/sh-id-platform/pkg/http"
httpPkg "github.com/polygonid/sh-id-platform/pkg/http"
"github.com/polygonid/sh-id-platform/pkg/pubsub"
"github.com/polygonid/sh-id-platform/pkg/reverse_hash"
)
Expand Down Expand Up @@ -102,7 +103,7 @@ func main() {
return
}

notificationGateway := gateways.NewPushNotificationClient(http.DefaultHTTPClientWithRetry)
notificationGateway := gateways.NewPushNotificationClient(httpPkg.DefaultHTTPClientWithRetry)
notificationService := services.NewNotification(notificationGateway, connectionsService, credentialsService)
ctxCancel, cancel := context.WithCancel(ctx)
defer func() {
Expand All @@ -120,6 +121,20 @@ func main() {
gracefulShutdown := make(chan os.Signal, 1)
signal.Notify(gracefulShutdown, syscall.SIGINT, syscall.SIGTERM)

go func() {
http.Handle("/status", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
_, err := w.Write([]byte("OK"))
if err != nil {
log.Error(ctx, "error writing response", "err", err)
}
}))
log.Info(ctx, "Starting server at port 3004")
err := http.ListenAndServe(":3004", nil)
if err != nil {
log.Error(ctx, "error starting server", "err", err)
}
}()

<-gracefulShutdown
}

Expand Down
15 changes: 15 additions & 0 deletions cmd/pending_publisher/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package main
import (
"context"
"math/big"
"net/http"
"os"
"os/signal"
"syscall"
Expand Down Expand Up @@ -190,6 +191,20 @@ func main() {
}
}(ctx)

go func() {
http.Handle("/status", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
_, err := w.Write([]byte("OK"))
if err != nil {
log.Error(ctx, "error writing response", "err", err)
}
}))
log.Info(ctx, "Starting server at port 3005")
err := http.ListenAndServe(":3005", nil)
if err != nil {
log.Error(ctx, "error starting server", "err", err)
}
}()

<-quit
log.Info(ctx, "finishing app")
cancel()
Expand Down
4 changes: 4 additions & 0 deletions infrastructure/local/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ services:
build:
context: ../../
dockerfile: ${DOCKER_FILE}
ports:
- "3004:3004"
env_file:
- ../../.env-api
- ../../.env-issuer
Expand All @@ -61,6 +63,8 @@ services:
build:
context: ../../
dockerfile: ${DOCKER_FILE}
ports:
- "3005:3005"
env_file:
- ../../.env-api
- ../../.env-issuer
Expand Down

0 comments on commit 696fdb9

Please sign in to comment.