Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions nexus/db-model/src/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,40 @@ pub struct InstanceRuntimeState {
pub time_last_auto_restarted: Option<DateTime<Utc>>,
}

impl InstanceRuntimeState {
/// Construct an `InstanceRuntimeState` with a new Nexus state, performing
/// the necessary accounting for a state change (such as bumping the
/// generation).
///
/// Fields not related to modifying the Nexus state remain unchanged from
/// `self`.
pub fn with_new_nexus_state(self, new_nexus_state: InstanceState) -> Self {
let Self {
// fields we overwrite
time_updated: _,
nexus_state: _,

// fields we modify
generation,

// fields we carry forward unchanged
propolis_id,
dst_propolis_id,
migration_id,
time_last_auto_restarted,
} = self;
Self {
time_updated: chrono::Utc::now(),
nexus_state: new_nexus_state,
generation: DbTypedGeneration(generation.0.next()),
propolis_id,
dst_propolis_id,
migration_id,
time_last_auto_restarted,
}
}
}

/// Configuration for automatic instance restarts.
#[derive(
Clone,
Expand Down
Loading
Loading