mirror of
https://github.com/fawney19/Aether.git
synced 2026-10-10 11:19:50 +08:00
feat: unify provider scheduling workspace
This commit is contained in:
@@ -1463,6 +1463,19 @@ pub trait ProviderCatalogReadRepository: Send + Sync {
|
||||
|
||||
#[async_trait]
|
||||
pub trait ProviderCatalogWriteRepository: Send + Sync {
|
||||
/// Create a provider and exclude it from every other existing routing group
|
||||
/// in one transaction. Implementations must fail closed if unsupported.
|
||||
async fn create_provider_in_routing_group(
|
||||
&self,
|
||||
_provider: &StoredProviderCatalogProvider,
|
||||
_shift_existing_priorities_from: Option<i32>,
|
||||
_routing_group_id: &str,
|
||||
) -> Result<StoredProviderCatalogProvider, crate::DataLayerError> {
|
||||
Err(crate::DataLayerError::InvalidConfiguration(
|
||||
"atomic provider creation in a routing group is not supported".to_string(),
|
||||
))
|
||||
}
|
||||
|
||||
async fn create_provider(
|
||||
&self,
|
||||
provider: &StoredProviderCatalogProvider,
|
||||
|
||||
@@ -58,6 +58,7 @@ pub struct CreateRoutingGroupRecord {
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Default)]
|
||||
pub struct UpdateRoutingGroupRecord {
|
||||
pub expected_version: Option<i64>,
|
||||
pub name: Option<String>,
|
||||
pub description: Option<Option<String>>,
|
||||
pub enabled: Option<bool>,
|
||||
@@ -244,6 +245,16 @@ pub fn apply_group_patch(
|
||||
group: &mut StoredRoutingGroup,
|
||||
patch: UpdateRoutingGroupRecord,
|
||||
) -> Result<(), crate::DataLayerError> {
|
||||
if patch
|
||||
.expected_version
|
||||
.is_some_and(|version| version != group.version)
|
||||
{
|
||||
return Err(crate::DataLayerError::InvalidInput(
|
||||
"routing_group_version_conflict".to_string(),
|
||||
));
|
||||
}
|
||||
let previous_version = group.version;
|
||||
let config_changed = patch.config_json.is_some();
|
||||
if let Some(name) = patch.name {
|
||||
if name.trim().is_empty() {
|
||||
return Err(crate::DataLayerError::InvalidInput(
|
||||
@@ -273,7 +284,13 @@ pub fn apply_group_patch(
|
||||
group.config_json = config_json;
|
||||
}
|
||||
if let Some(version) = patch.version {
|
||||
group.version = version.max(1);
|
||||
group.version = if config_changed {
|
||||
version.max(previous_version.saturating_add(1))
|
||||
} else {
|
||||
version.max(previous_version)
|
||||
};
|
||||
} else if config_changed {
|
||||
group.version = previous_version.saturating_add(1);
|
||||
}
|
||||
if let Some(published_at) = patch.published_at {
|
||||
group.published_at = published_at;
|
||||
|
||||
Reference in New Issue
Block a user