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 return
} }
// after creating the source, we should do a bulk import // after creating the source, we should do a bulk import (in the background)
summary, err := SyncSourceResources(c, logger, databaseRepo, &sourceCred)
summary, err := SyncSourceResources(context.WithValue(c.Request.Context(), pkg.ContextKeyTypeAuthUsername, c.Value(pkg.ContextKeyTypeAuthUsername).(string)), logger, databaseRepo, &sourceCred)
if err != nil { if err != nil {
c.JSON(http.StatusInternalServerError, gin.H{"success": false}) c.JSON(http.StatusInternalServerError, gin.H{"success": false})
return return
@ -164,8 +165,8 @@ func SourceSync(c *gin.Context) {
return return
} }
// after creating the source, we should do a bulk import // after creating the source, we should do a bulk import (in the background)
summary, err := SyncSourceResources(c, logger, databaseRepo, sourceCred) summary, err := SyncSourceResources(context.WithValue(c.Request.Context(), pkg.ContextKeyTypeAuthUsername, c.Value(pkg.ContextKeyTypeAuthUsername).(string)), logger, databaseRepo, sourceCred)
if err != nil { if err != nil {
c.JSON(http.StatusInternalServerError, gin.H{"success": false}) c.JSON(http.StatusInternalServerError, gin.H{"success": false})
return return

View File

@ -1,11 +1,9 @@
package middleware package middleware
import ( import (
"fmt"
"github.com/fastenhealth/fasten-onprem/backend/pkg" "github.com/fastenhealth/fasten-onprem/backend/pkg"
"github.com/fastenhealth/fasten-onprem/backend/pkg/web/sse" "github.com/fastenhealth/fasten-onprem/backend/pkg/web/sse"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"time"
) )
func SSEHeaderMiddleware() gin.HandlerFunc { func SSEHeaderMiddleware() gin.HandlerFunc {
@ -23,18 +21,6 @@ func SSEEventBusServerMiddleware() gin.HandlerFunc {
// get reference to streaming server singleton // get reference to streaming server singleton
bus := sse.GetEventBusServer() 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) { return func(c *gin.Context) {
// Initialize client channel // Initialize client channel
clientChan := make(sse.ClientChan) 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/config"
"github.com/fastenhealth/fasten-onprem/backend/pkg/web/handler" "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/middleware"
"github.com/fastenhealth/fasten-onprem/backend/pkg/web/sse"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
"net/http" "net/http"
@ -36,6 +37,10 @@ func (ae *AppEngine) Setup() (*gin.RouterGroup, *gin.Engine) {
//TODO: //TODO:
// check if the /web folder is populated. // check if the /web folder is populated.
// check if access to database // check if access to database
bus := sse.GetEventBusServer()
bus.Message <- "sse heartbeat"
c.JSON(http.StatusOK, gin.H{ c.JSON(http.StatusOK, gin.H{
"success": true, "success": true,
}) })