ModelServerless godoc @Security ApiKey @Summary run model as serverless service @Tags Model @Accept json @Produce json @Param namespace path string true "namespace" @Param name path string true "name" @Param current_user query string true "current_us
(ctx *gin.Context)
| 1231 | // @Failure 500 {object} types.APIInternalServerError "Internal server error" |
| 1232 | // @Router /models/{namespace}/{name}/serverless [post] |
| 1233 | func (h *ModelHandler) DeployServerless(ctx *gin.Context) { |
| 1234 | currentUser := httpbase.GetCurrentUser(ctx) |
| 1235 | if currentUser == "" { |
| 1236 | httpbase.UnauthorizedError(ctx, component.ErrUserNotFound) |
| 1237 | return |
| 1238 | } |
| 1239 | |
| 1240 | namespace, name, err := common.GetNamespaceAndNameFromContext(ctx) |
| 1241 | if err != nil { |
| 1242 | slog.Error("failed to get namespace from context", "error", err) |
| 1243 | httpbase.BadRequest(ctx, err.Error()) |
| 1244 | return |
| 1245 | } |
| 1246 | |
| 1247 | var req types.ModelRunReq |
| 1248 | if err := ctx.ShouldBindJSON(&req); err != nil { |
| 1249 | slog.Error("Bad request format", "error", err) |
| 1250 | httpbase.BadRequest(ctx, err.Error()) |
| 1251 | return |
| 1252 | } |
| 1253 | |
| 1254 | if req.Revision == "" { |
| 1255 | req.Revision = "main" // default repo branch |
| 1256 | } |
| 1257 | |
| 1258 | if req.MinReplica < 0 || req.MaxReplica < 0 || req.MinReplica > req.MaxReplica { |
| 1259 | slog.Error("Bad request setting for replica", slog.Any("MinReplica", req.MinReplica), slog.Any("MaxReplica", req.MaxReplica)) |
| 1260 | httpbase.BadRequest(ctx, "Bad request setting for replica") |
| 1261 | return |
| 1262 | } |
| 1263 | |
| 1264 | deployReq := types.DeployActReq{ |
| 1265 | Namespace: namespace, |
| 1266 | Name: name, |
| 1267 | CurrentUser: currentUser, |
| 1268 | DeployType: types.ServerlessType, |
| 1269 | } |
| 1270 | |
| 1271 | req.SecureLevel = 1 // public for serverless |
| 1272 | deployID, err := h.c.Deploy(ctx, deployReq, req) |
| 1273 | if err != nil { |
| 1274 | slog.Error("failed to deploy model as serverless", slog.String("namespace", namespace), |
| 1275 | slog.String("name", name), slog.Any("currentUser", currentUser), slog.Any("req", req), slog.Any("error", err)) |
| 1276 | httpbase.ServerError(ctx, err) |
| 1277 | return |
| 1278 | } |
| 1279 | |
| 1280 | slog.Debug("deploy model as serverless created", slog.String("namespace", namespace), |
| 1281 | slog.String("name", name), slog.Int64("deploy_id", deployID)) |
| 1282 | |
| 1283 | // return deploy_id |
| 1284 | response := types.DeployRepo{DeployID: deployID} |
| 1285 | |
| 1286 | httpbase.OK(ctx, response) |
| 1287 | } |
| 1288 | |
| 1289 | // StartServerless godoc |
| 1290 | // @Security ApiKey |
nothing calls this directly
no test coverage detected