Skip to content

Commit

Permalink
Creating compareBuilds function
Browse files Browse the repository at this point in the history
  • Loading branch information
lsergio committed Aug 12, 2024
1 parent 58c814c commit c4ce7ff
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions pkg/apis/camel/v1/build_types_support.go
Original file line number Diff line number Diff line change
Expand Up @@ -326,25 +326,17 @@ func (bl BuildList) HasMatchingBuild(build *Build) (bool, *Build) {
if allMatching && len(required) == len(dependencies) {
// seems like both builds require exactly the same list of dependencies
// additionally check for the creation timestamp
if b.CreationTimestamp.Before(&build.CreationTimestamp) {
if compareBuilds(&b, build) < 0 {
return true, &b
} else if b.CreationTimestamp.Equal(&build.CreationTimestamp) {
if strings.Compare(b.Name, build.Name) < 0 {
return true, &b
}
}

} else if !allMatching && commonDependencies > 0 {
// there are common dependencies. let's compare the total number of dependencies
// in each build. whichever build has less dependencies should run first
if len(dependencies) < len(required) {
return true, &b
} else if len(dependencies) == len(required) {
// same number of total dependencies.
if b.CreationTimestamp.Before(&build.CreationTimestamp) {
return true, &b
} else if b.CreationTimestamp.Equal(&build.CreationTimestamp) &&
strings.Compare(b.Name, build.Name) < 0 {
if compareBuilds(&b, build) < 0 {
return true, &b
}
}
Expand All @@ -355,3 +347,13 @@ func (bl BuildList) HasMatchingBuild(build *Build) (bool, *Build) {

return false, nil
}

func compareBuilds(b1 *Build, b2 *Build) int {
if b1.CreationTimestamp.Before(&b2.CreationTimestamp) {
return -1
} else if b2.CreationTimestamp.Before(&b1.CreationTimestamp) {
return 1
} else {
return strings.Compare(b1.Name, b2.Name)
}
}

0 comments on commit c4ce7ff

Please sign in to comment.