Skip to content

Commit dd19a39

Browse files
committed
refactor(components): plumbing a context
1 parent 2dfa5e8 commit dd19a39

File tree

2 files changed

+14
-11
lines changed

2 files changed

+14
-11
lines changed

src/ops/storages/neo4j.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -696,6 +696,7 @@ impl components::SetupOperator for SetupComponentOperator {
696696
type Key = ComponentKey;
697697
type State = ComponentState;
698698
type SetupState = SetupState;
699+
type Context = ();
699700

700701
fn describe_key(&self, key: &Self::Key) -> String {
701702
format!("{} {}", key.kind.describe(), key.name)
@@ -724,7 +725,7 @@ impl components::SetupOperator for SetupComponentOperator {
724725
current == desired
725726
}
726727

727-
async fn create(&self, state: &ComponentState) -> Result<()> {
728+
async fn create(&self, state: &ComponentState, _context: &Self::Context) -> Result<()> {
728729
let graph = self.graph_pool.get_graph(&self.conn_spec).await?;
729730
let key = state.key();
730731
let qualifier = CORE_ELEMENT_MATCHER_VAR;
@@ -762,7 +763,7 @@ impl components::SetupOperator for SetupComponentOperator {
762763
Ok(graph.run(query).await?)
763764
}
764765

765-
async fn delete(&self, key: &ComponentKey) -> Result<()> {
766+
async fn delete(&self, key: &ComponentKey, _context: &Self::Context) -> Result<()> {
766767
let graph = self.graph_pool.get_graph(&self.conn_spec).await?;
767768
let query = neo4rs::query(&format!(
768769
"DROP {kind} {name} IF EXISTS",
@@ -1131,7 +1132,7 @@ impl StorageFactoryBase for Factory {
11311132
}
11321133
}
11331134

1134-
apply_component_changes(components).await?;
1135+
apply_component_changes(components, &()).await?;
11351136
Ok(())
11361137
}
11371138
}

src/setup/components.rs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,21 @@ pub trait SetupOperator: 'static + Send + Sync {
1111
type Key: Debug + Hash + Eq + Clone + Send + Sync;
1212
type State: State<Self::Key>;
1313
type SetupState: Send + Sync + IntoIterator<Item = Self::State>;
14+
type Context: Sync;
1415

1516
fn describe_key(&self, key: &Self::Key) -> String;
1617

1718
fn describe_state(&self, state: &Self::State) -> String;
1819

1920
fn is_up_to_date(&self, current: &Self::State, desired: &Self::State) -> bool;
2021

21-
async fn create(&self, state: &Self::State) -> Result<()>;
22+
async fn create(&self, state: &Self::State, context: &Self::Context) -> Result<()>;
2223

23-
async fn delete(&self, key: &Self::Key) -> Result<()>;
24+
async fn delete(&self, key: &Self::Key, context: &Self::Context) -> Result<()>;
2425

25-
async fn update(&self, state: &Self::State) -> Result<()> {
26-
self.delete(&state.key()).await?;
27-
self.create(state).await
26+
async fn update(&self, state: &Self::State, context: &Self::Context) -> Result<()> {
27+
self.delete(&state.key(), context).await?;
28+
self.create(state, context).await
2829
}
2930
}
3031

@@ -150,21 +151,22 @@ impl<D: SetupOperator + Send + Sync> ResourceSetupStatus for SetupStatus<D> {
150151

151152
pub async fn apply_component_changes<D: SetupOperator>(
152153
changes: Vec<&SetupStatus<D>>,
154+
context: &D::Context,
153155
) -> Result<()> {
154156
// First delete components that need to be removed
155157
for change in changes.iter() {
156158
for key in &change.keys_to_delete {
157-
change.desc.delete(key).await?;
159+
change.desc.delete(key, context).await?;
158160
}
159161
}
160162

161163
// Then upsert components that need to be updated
162164
for change in changes.iter() {
163165
for state in &change.states_to_upsert {
164166
if state.already_exists {
165-
change.desc.update(&state.state).await?;
167+
change.desc.update(&state.state, context).await?;
166168
} else {
167-
change.desc.create(&state.state).await?;
169+
change.desc.create(&state.state, context).await?;
168170
}
169171
}
170172
}

0 commit comments

Comments
 (0)