Skip to content

Commit

Permalink
logs: improve resource logs
Browse files Browse the repository at this point in the history
Signed-off-by: ljedrz <[email protected]>
  • Loading branch information
ljedrz committed Mar 30, 2022
1 parent 7f5b349 commit 1aafebd
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions environment/src/helpers/resources.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,15 @@ impl Resources {
while let Some(request) = receiver.recv().await {
match request {
ResourceRequest::Register(resource, id) => {
let resource_name = match resource {
Resource::Task(..) => "task",
Resource::Thread(..) => "thread",
};

if resources.insert(id, resource).is_some() {
error!("A resource with the id {} already exists!", id);
error!("A resource with id {} already exists!", id);
} else {
trace!("Registered a resource under the id {}", id);
trace!("Registered a {} as resource {}", resource_name, id);
}
}
ResourceRequest::Deregister(id) => {
Expand All @@ -115,11 +120,11 @@ impl Resources {
// to-be-aborted task to free its resources.
tokio::spawn(async move {
sleep(Duration::from_secs(1)).await;
trace!("Aborting resource with the id {}", id);
trace!("Aborting resource with id {}", id);
resource.abort().await;
});
} else {
error!("Resource with the id {} was not found", id);
error!("Resource with id {} was not found", id);
}
}
ResourceRequest::Shutdown => break,
Expand All @@ -141,7 +146,7 @@ impl Resources {
resources.sort_unstable_by_key(|(id, _res)| *id);

for (id, resource) in resources.into_iter().rev() {
trace!("Aborting resource with the id {}", id);
trace!("Aborting resource with id {}", id);
resource.abort().await;
}
});
Expand Down

0 comments on commit 1aafebd

Please sign in to comment.