deriving background context based on Gin Contex.

Removed testing message bus heartbeats -> moved to /health endpoint.
This commit is contained in:
Jason Kulatunga 2023-09-07 21:54:25 -07:00
parent b344469caa
commit 8ff42142fb
3 changed files with 10 additions and 18 deletions

View File

@ -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
@ -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

View File

@ -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 {
@ -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)

View File

@ -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"
@ -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,
})