|
| 1 | +// Copyright (c) 2025 Uber Technologies, Inc. |
| 2 | +// |
| 3 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +// you may not use this file except in compliance with the License. |
| 5 | +// You may obtain a copy of the License at |
| 6 | +// |
| 7 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +// |
| 9 | +// Unless required by applicable law or agreed to in writing, software |
| 10 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +// See the License for the specific language governing permissions and |
| 13 | +// limitations under the License. |
| 14 | + |
| 15 | +package entity |
| 16 | + |
| 17 | +// BatchStatus is the state of a validation batch as it moves through the pipeline. |
| 18 | +type BatchStatus string |
| 19 | + |
| 20 | +const ( |
| 21 | + // BatchStatusUnknown is the unreachable default. It should never be seen in the system. |
| 22 | + BatchStatusUnknown BatchStatus = "" |
| 23 | + // BatchStatusPending means the batch has been created but speculate has not yet run. |
| 24 | + BatchStatusPending BatchStatus = "pending" |
| 25 | + // BatchStatusBuilding means the batch is moving through the speculate→build→buildsignal→bisect cycle. |
| 26 | + BatchStatusBuilding BatchStatus = "building" |
| 27 | + // BatchStatusSucceeded means all commits in the batch's range have been validated green. |
| 28 | + BatchStatusSucceeded BatchStatus = "succeeded" |
| 29 | + // BatchStatusFailed means an offending commit in the range has been isolated and marked failed. |
| 30 | + BatchStatusFailed BatchStatus = "failed" |
| 31 | +) |
| 32 | + |
| 33 | +// IsBatchStatusTerminal returns true if the batch has reached a final state. |
| 34 | +func IsBatchStatusTerminal(s BatchStatus) bool { |
| 35 | + return s == BatchStatusSucceeded || s == BatchStatusFailed |
| 36 | +} |
| 37 | + |
| 38 | +// Batch is a contiguous range of trunk commits submitted for validation together. |
| 39 | +// The range spans from FromSHA (oldest, inclusive) to ToSHA (newest, inclusive) |
| 40 | +// and represents all commits since the last known green on the branch. |
| 41 | +// Bisection creates sub-range batches from the same type — there is no separate |
| 42 | +// bisection entity; the state of the search lives in the ordinary batch results. |
| 43 | +type Batch struct { |
| 44 | + // ID is the unique identifier for this batch. |
| 45 | + ID string |
| 46 | + // FromSHA is the oldest commit SHA in the validation range (inclusive). |
| 47 | + FromSHA string |
| 48 | + // ToSHA is the newest commit SHA in the validation range (inclusive). |
| 49 | + ToSHA string |
| 50 | + // Repository is the repository this batch validates. |
| 51 | + Repository string |
| 52 | + // Branch is the branch this batch validates. |
| 53 | + Branch string |
| 54 | + // Status is the current state of this batch. |
| 55 | + Status BatchStatus |
| 56 | + // Version is incremented on each update and used for optimistic locking. |
| 57 | + // Version arithmetic lives in the controller; the store performs a pure conditional write. |
| 58 | + Version int32 |
| 59 | + // CreatedAt is the time this batch was created, in milliseconds since epoch. |
| 60 | + CreatedAt int64 |
| 61 | + // UpdatedAt is the time this batch was last updated, in milliseconds since epoch. |
| 62 | + UpdatedAt int64 |
| 63 | +} |
0 commit comments