feat: add priority demotion controls
This commit is contained in:
@@ -44,6 +44,44 @@ func (s *Server) updateRunnerPolicy(w http.ResponseWriter, r *http.Request) {
|
||||
writeJSON(w, http.StatusOK, item)
|
||||
}
|
||||
|
||||
type updatePlatformDynamicPriorityRequest struct {
|
||||
DynamicPriority *int `json:"dynamicPriority"`
|
||||
Reset bool `json:"reset"`
|
||||
}
|
||||
|
||||
func (s *Server) updatePlatformDynamicPriority(w http.ResponseWriter, r *http.Request) {
|
||||
var input updatePlatformDynamicPriorityRequest
|
||||
if err := json.NewDecoder(r.Body).Decode(&input); err != nil {
|
||||
writeError(w, http.StatusBadRequest, "invalid json body")
|
||||
return
|
||||
}
|
||||
var dynamicPriority *int
|
||||
if input.Reset {
|
||||
dynamicPriority = nil
|
||||
} else {
|
||||
if input.DynamicPriority == nil {
|
||||
writeError(w, http.StatusBadRequest, "dynamicPriority is required unless reset is true")
|
||||
return
|
||||
}
|
||||
if *input.DynamicPriority < 0 {
|
||||
writeError(w, http.StatusBadRequest, "dynamicPriority must be greater than or equal to 0")
|
||||
return
|
||||
}
|
||||
dynamicPriority = input.DynamicPriority
|
||||
}
|
||||
item, err := s.store.UpdatePlatformDynamicPriority(r.Context(), r.PathValue("platformID"), dynamicPriority)
|
||||
if err != nil {
|
||||
if store.IsNotFound(err) {
|
||||
writeError(w, http.StatusNotFound, "platform not found")
|
||||
return
|
||||
}
|
||||
s.logger.Error("update platform dynamic priority failed", "error", err)
|
||||
writeError(w, http.StatusInternalServerError, "update platform dynamic priority failed")
|
||||
return
|
||||
}
|
||||
writeJSON(w, http.StatusOK, item)
|
||||
}
|
||||
|
||||
func (s *Server) createRuntimePolicySet(w http.ResponseWriter, r *http.Request) {
|
||||
var input store.RuntimePolicySetInput
|
||||
if err := json.NewDecoder(r.Body).Decode(&input); err != nil {
|
||||
|
||||
Reference in New Issue
Block a user