Skip to content

Commit

Permalink
deriving background context based on Gin Contex.
Browse files Browse the repository at this point in the history
Removed testing message bus heartbeats -> moved to /health endpoint.
  • Loading branch information
AnalogJ committed Sep 10, 2023
1 parent b344469 commit 8ff4214
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 18 deletions.
9 changes: 5 additions & 4 deletions backend/pkg/web/handler/source.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,9 @@ func CreateSource(c *gin.Context) {
return
}

// after creating the source, we should do a bulk import
summary, err := SyncSourceResources(c, logger, databaseRepo, &sourceCred)
// after creating the source, we should do a bulk import (in the background)

summary, err := SyncSourceResources(context.WithValue(c.Request.Context(), pkg.ContextKeyTypeAuthUsername, c.Value(pkg.ContextKeyTypeAuthUsername).(string)), logger, databaseRepo, &sourceCred)
if err != nil {
c.JSON(http.StatusInternalServerError, gin.H{"success": false})
return
Expand All @@ -164,8 +165,8 @@ func SourceSync(c *gin.Context) {
return
}

// after creating the source, we should do a bulk import
summary, err := SyncSourceResources(c, logger, databaseRepo, sourceCred)
// after creating the source, we should do a bulk import (in the background)
summary, err := SyncSourceResources(context.WithValue(c.Request.Context(), pkg.ContextKeyTypeAuthUsername, c.Value(pkg.ContextKeyTypeAuthUsername).(string)), logger, databaseRepo, sourceCred)
if err != nil {
c.JSON(http.StatusInternalServerError, gin.H{"success": false})
return
Expand Down
14 changes: 0 additions & 14 deletions backend/pkg/web/middleware/server_sent_event.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
package middleware

import (
"fmt"
"github.com/fastenhealth/fasten-onprem/backend/pkg"
"github.com/fastenhealth/fasten-onprem/backend/pkg/web/sse"
"github.com/gin-gonic/gin"
"time"
)

func SSEHeaderMiddleware() gin.HandlerFunc {
Expand All @@ -23,18 +21,6 @@ func SSEEventBusServerMiddleware() gin.HandlerFunc {
// get reference to streaming server singleton
bus := sse.GetEventBusServer()

///TODO: testing only
go func() {
for {
time.Sleep(time.Second * 10)
now := time.Now().Format("2006-01-02 15:04:05")
currentTime := fmt.Sprintf("The Current Time Is %v", now)

// Send current time to clients message channel
bus.Message <- currentTime
}
}()

return func(c *gin.Context) {
// Initialize client channel
clientChan := make(sse.ClientChan)
Expand Down
5 changes: 5 additions & 0 deletions backend/pkg/web/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"github.com/fastenhealth/fasten-onprem/backend/pkg/config"
"github.com/fastenhealth/fasten-onprem/backend/pkg/web/handler"
"github.com/fastenhealth/fasten-onprem/backend/pkg/web/middleware"
"github.com/fastenhealth/fasten-onprem/backend/pkg/web/sse"
"github.com/gin-gonic/gin"
"github.com/sirupsen/logrus"
"net/http"
Expand Down Expand Up @@ -36,6 +37,10 @@ func (ae *AppEngine) Setup() (*gin.RouterGroup, *gin.Engine) {
//TODO:
// check if the /web folder is populated.
// check if access to database

bus := sse.GetEventBusServer()
bus.Message <- "sse heartbeat"

c.JSON(http.StatusOK, gin.H{
"success": true,
})
Expand Down

0 comments on commit 8ff4214

Please sign in to comment.