Skip to content

Commit

Permalink
Compare usage to quota to determine overage status
Browse files Browse the repository at this point in the history
  • Loading branch information
John Wregglesworth committed Nov 17, 2022
1 parent 6a751da commit 712d6ef
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions internal/limits.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,20 +193,28 @@ func validateJobLimits(user string, defaultJobLimit, jobCount int, jobLimit *int
return http.StatusBadRequest, buildLimitError(code, msg, defaultJobLimit, jobCount, jobLimit)

case overages != nil && len(overages.Overages) != 0:
var inOverage bool
code := "ERR_RESOURCE_OVERAGE"
msg := fmt.Sprintf("%s has resource overages.", user)
details := make(map[string]interface{})

for _, ov := range overages.Overages {
details[ov.ResourceName] = fmt.Sprintf("quota: %f, usage: %f", ov.Quota, ov.Usage)
if ov.Usage >= ov.Quota {
inOverage = true
details[ov.ResourceName] = fmt.Sprintf("quota: %f, usage: %f", ov.Quota, ov.Usage)
}
}

return http.StatusBadRequest, common.ErrorResponse{
ErrorCode: code,
Message: msg,
Details: &details,
if inOverage {
msg := fmt.Sprintf("%s has resource overages.", user)
return http.StatusBadRequest, common.ErrorResponse{
ErrorCode: code,
Message: msg,
Details: &details,
}
}

return http.StatusOK, nil

// In every other case, we can permit the job to be launched.
default:
return http.StatusOK, nil
Expand Down

0 comments on commit 712d6ef

Please sign in to comment.