diff --git a/database/function.go b/database/function.go index 0936478..4fad940 100644 --- a/database/function.go +++ b/database/function.go @@ -5,8 +5,13 @@ import ( ) type Function struct { - ID uuid.UUID `json:"id" ,gorm:"primarykey;type:uuid;default:gen_random_uuid()"` - Name string `json:"name"` - Description string `json:"description"` - Language string `json:"language"` + ID uuid.UUID `json:"id" ,gorm:"primarykey;type:uuid;default:gen_random_uuid()"` + Name string `json:"name"` + Description string `json:"description"` + Language string `json:"language"` + + OwnerID int `json:"owner_id"` + Owner User `json:"-"` + + FunctionStates []FunctionState `json:"-"` } diff --git a/database/functionState.go b/database/functionState.go index fc869e9..d76e30c 100644 --- a/database/functionState.go +++ b/database/functionState.go @@ -8,13 +8,13 @@ import ( type FunctionState struct { gorm.Model ID uuid.UUID `json:"id" ,gorm:"primarykey;type:uuid;default:gen_random_uuid()"` - Code string `json:"code"` - Status string `json:"status"` - Address string `json:"address"` - Port uint16 `json:"port"` - // OwnerID + Status string `json:"status"` + Address string `json:"address"` + Port uint16 `json:"port"` + + FunctionID uuid.UUID `json:"function_id"` } func (FunctionState) TableName() string { - return "function_state" + return "function_states" } diff --git a/routes/function/controller.go b/routes/function/controller.go index 7efc4e3..7f7ff13 100644 --- a/routes/function/controller.go +++ b/routes/function/controller.go @@ -178,7 +178,7 @@ func (c *Controller) RunFunction(ctx *gin.Context) { } var fn database.FunctionState - err = c.DB.Where(&database.FunctionState{ID: fnID}).First(&fn).Error + err = c.DB.Where(&database.FunctionState{FunctionID: fnID}).First(&fn).Error if err != nil && errors.Is(err, gorm.ErrRecordNotFound) { ctx.AbortWithStatusJSON(404, gin.H{"error": "Function not found"}) @@ -190,20 +190,20 @@ func (c *Controller) RunFunction(ctx *gin.Context) { time.Sleep(100 * time.Millisecond) for attempts := 0; attempts < 5; attempts++ { - err = c.DB.Where(&database.FunctionState{ID: fnID, Status: "Ready"}).First(&fn).Error + err = c.DB.Where(&database.FunctionState{FunctionID: fnID, Status: "Ready"}).First(&fn).Error if !errors.Is(err, gorm.ErrRecordNotFound) { log.Println(err) ctx.AbortWithStatusJSON(500, gin.H{"error": err.Error()}) return } else { - log.Println("Function", fn.ID, "is not ready yet... Retrying") + log.Println("Function", fn.FunctionID, "is not ready yet... Retrying") time.Sleep(100 * time.Millisecond) } if fn.Status == "Ready" { - log.Println("Function", fn.ID, "is ready") + log.Println("Function", fn.FunctionID, "is ready") break };