mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
chore: improve build deadline code (#19203)
- Adds/improves a lot of comments to make the autostop calculation code clearer - Changes the behavior of the enterprise template schedule store to match the behavior of the workspace TTL endpoint when the new TTL is zero - Fixes a bug in the workspace TTL endpoint where it could unset the build deadline, even though a max_deadline was specified - Adds a new constraint to the workspace_builds table that enforces the deadline is non-zero and below the max_deadline if it is set - Adds CHECK constraint enum generation to scripts/dbgen, used for testing the above constraint - Adds Dean and Danielle as CODEOWNERS for the autostop calculation code
This commit is contained in:
@@ -59,6 +59,28 @@ func IsForeignKeyViolation(err error, foreignKeyConstraints ...ForeignKeyConstra
|
||||
return false
|
||||
}
|
||||
|
||||
// IsCheckViolation checks if the error is due to a check violation. If one or
|
||||
// more specific check constraints are given as arguments, the error must be
|
||||
// caused by one of them. If no constraints are given, this function returns
|
||||
// true for any check violation.
|
||||
func IsCheckViolation(err error, checkConstraints ...CheckConstraint) bool {
|
||||
var pqErr *pq.Error
|
||||
if errors.As(err, &pqErr) {
|
||||
if pqErr.Code.Name() == "check_violation" {
|
||||
if len(checkConstraints) == 0 {
|
||||
return true
|
||||
}
|
||||
for _, cc := range checkConstraints {
|
||||
if pqErr.Constraint == string(cc) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
// IsQueryCanceledError checks if the error is due to a query being canceled.
|
||||
func IsQueryCanceledError(err error) bool {
|
||||
var pqErr *pq.Error
|
||||
|
||||
Reference in New Issue
Block a user