Skip to content

Commit

Permalink
wip datarace
Browse files Browse the repository at this point in the history
  • Loading branch information
leon3s committed Jan 13, 2024
1 parent fbb6e13 commit e9e6876
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
8 changes: 6 additions & 2 deletions bin/nanocld/src/models/task_manager.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
use std::{
sync::{Arc, Mutex},
collections::HashMap,
future::IntoFuture,

Check warning on line 4 in bin/nanocld/src/models/task_manager.rs

View workflow job for this annotation

GitHub Actions / clippy

unused imports: `future::IntoFuture`, `ops::Deref`

warning: unused imports: `future::IntoFuture`, `ops::Deref` --> bin/nanocld/src/models/task_manager.rs:4:3 | 4 | future::IntoFuture, | ^^^^^^^^^^^^^^^^^^ 5 | ops::Deref, | ^^^^^^^^^^ | = note: `#[warn(unused_imports)]` on by default
ops::Deref,
};

use ntex::{rt, web};
use futures_util::Future;
use futures_util::{Future, FutureExt};

Check warning on line 9 in bin/nanocld/src/models/task_manager.rs

View workflow job for this annotation

GitHub Actions / clippy

unused import: `FutureExt`

warning: unused import: `FutureExt` --> bin/nanocld/src/models/task_manager.rs:9:28 | 9 | use futures_util::{Future, FutureExt}; | ^^^^^^^^^

use nanocl_error::io::{IoResult, IoError};

Expand Down Expand Up @@ -43,7 +45,8 @@ impl TaskManager {
let mut tasks = tasks
.lock()
.map_err(|err| IoError::interupted("Task", err.to_string().as_str()))?;
tasks.insert(key, task);
log::debug!("Adding task: {key} {}", task.kind);
tasks.insert(key.clone(), task.clone());
Ok::<_, IoError>(())
})
.await?;
Expand All @@ -59,6 +62,7 @@ impl TaskManager {
.map_err(|err| IoError::interupted("Task", err.to_string().as_str()))?;
let task = tasks.get(&key);
if let Some(task) = task {
log::debug!("Removing task: {key} {}", task.kind);
task.fut.abort();
}
tasks.remove(&key);
Expand Down
5 changes: 5 additions & 0 deletions bin/nanocld/src/subsystem/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,11 @@ async fn update(e: &Event, state: &SystemState) -> IoResult<()> {
let mut error = None;
match actor.kind {

Check warning on line 286 in bin/nanocld/src/subsystem/event.rs

View check run for this annotation

Codecov / codecov/patch

bin/nanocld/src/subsystem/event.rs#L284-L286

Added lines #L284 - L286 were not covered by tests
EventActorKind::Cargo => {
let task_key = format!("{}@{key}", &actor.kind);
let curr_task = state.task_manager.get_task(&task_key).await;
if curr_task.is_some() {
state.task_manager.remove_task(&task_key).await?;
}
let cargo = CargoDb::transform_read_by_pk(&key, &state.pool).await?;
let processes = ProcessDb::read_by_kind_key(&key, &state.pool).await?;

Check warning on line 294 in bin/nanocld/src/subsystem/event.rs

View check run for this annotation

Codecov / codecov/patch

bin/nanocld/src/subsystem/event.rs#L288-L294

Added lines #L288 - L294 were not covered by tests
// Create instance with the new spec
Expand Down

0 comments on commit e9e6876

Please sign in to comment.