pub enum PolicyMode {
MonitorOnly,
Autoscale(AutoscaleConfig),
}Expand description
D19, as an enforced invariant rather than a convention.
04-subsystem-contracts.md:
- “
MonitorOnlyrequiresrouting_labelsandmax_capacityto beNone.” - “
Autoscalerequires both to beSome.”
The contract writes those as three flat, independently-Optional fields on
ScalePolicy, which admits four combinations of which two are illegal. This
enum admits exactly the two legal ones, so the illegal pair has no
representation — b1 asks for that explicitly: “Prefer a representation
where the illegal combination cannot be built at all over one that is merely
validated on the way in.”
The flat shape is still reachable: PolicyMode::routing_labels,
PolicyMode::min_capacity, and PolicyMode::max_capacity return exactly
the Options the contract names, and PolicyMode::from_persisted rebuilds
the mode from them. That is b2’s load path, and it is where a hand-edited
database row is rejected.
Variants§
MonitorOnly
Contributes runners and workflow counts to the dashboard; owns no routing label; skipped entirely by reconciliation.
Autoscale(AutoscaleConfig)
Starts runners, up to max_capacity and the host ceiling.
Implementations§
Source§impl PolicyMode
impl PolicyMode
pub const fn monitor_only() -> Self
Sourcepub fn autoscale(
routing_labels: RoutingLabels,
min_capacity: u16,
max_capacity: NonZeroU16,
) -> Result<Self, PolicyError>
pub fn autoscale( routing_labels: RoutingLabels, min_capacity: u16, max_capacity: NonZeroU16, ) -> Result<Self, PolicyError>
Sourcepub fn from_persisted(
routing_labels: Option<RoutingLabels>,
min_capacity: u16,
max_capacity: Option<NonZeroU16>,
) -> Result<Self, PolicyError>
pub fn from_persisted( routing_labels: Option<RoutingLabels>, min_capacity: u16, max_capacity: Option<NonZeroU16>, ) -> Result<Self, PolicyError>
Rebuild the mode from the flat persisted shape.
This is the gate b2 puts every load through. All four combinations of
routing_labels/max_capacity arrive here, and two of them are refused
with a named error rather than being coerced into something plausible.
§Errors
Each illegal shape gets its own variant, so b2 can say which column of
which row is wrong rather than “invalid policy”.
Sourcepub const fn routing_labels(&self) -> Option<&RoutingLabels>
pub const fn routing_labels(&self) -> Option<&RoutingLabels>
The contract’s routing_labels: Option<NonEmpty<Label>>, in Option
form.
pub const fn min_capacity(&self) -> u16
pub const fn max_capacity(&self) -> Option<NonZeroU16>
pub const fn autoscale_config(&self) -> Option<&AutoscaleConfig>
pub const fn is_autoscale(&self) -> bool
pub const fn is_monitor_only(&self) -> bool
Trait Implementations§
Source§impl Clone for PolicyMode
impl Clone for PolicyMode
Source§fn clone(&self) -> PolicyMode
fn clone(&self) -> PolicyMode
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more