improve the resource busy locks

This commit is contained in:
mbecker20
2024-04-27 15:09:30 -07:00
parent 0fc6e89ffe
commit fab4e8e534
65 changed files with 1179 additions and 1349 deletions

View File

@@ -16,7 +16,7 @@ use crate::{
resource::StateResource,
update::{add_update, make_update, update_update},
},
state::State,
state::{action_states, State},
};
#[async_trait]
@@ -34,6 +34,17 @@ impl Resolve<RunProcedure, User> for State {
)
.await?;
// get the action state for the procedure (or insert default).
let action_state = action_states()
.procedure
.get_or_insert_default(&procedure.id)
.await;
// This will set action state back to default when dropped.
// Will also check to ensure procedure not already busy before updating.
let _action_guard =
action_state.update(|state| state.running = true).await?;
let mut update =
make_update(&procedure, Operation::RunProcedure, &user);
update.in_progress();