diff --git a/backend/pkg/web/handler/source.go b/backend/pkg/web/handler/source.go index 94811160..559832d9 100644 --- a/backend/pkg/web/handler/source.go +++ b/backend/pkg/web/handler/source.go @@ -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 diff --git a/backend/pkg/web/middleware/server_sent_event.go b/backend/pkg/web/middleware/server_sent_event.go index fc427d3c..9e7811ce 100644 --- a/backend/pkg/web/middleware/server_sent_event.go +++ b/backend/pkg/web/middleware/server_sent_event.go @@ -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) diff --git a/backend/pkg/web/server.go b/backend/pkg/web/server.go index 776afd85..6013f43e 100644 --- a/backend/pkg/web/server.go +++ b/backend/pkg/web/server.go @@ -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, })