chore: opt code under persistent_cache_task (#1098)
chroe: opt code under persistent_cache_task Signed-off-by: cormick <cormick1080@gmail.com>
This commit is contained in:
parent
ad335784fe
commit
938d17c0cf
|
|
@ -105,7 +105,7 @@ impl PersistentCacheTask {
|
||||||
id_generator,
|
id_generator,
|
||||||
storage,
|
storage,
|
||||||
scheduler_client,
|
scheduler_client,
|
||||||
piece: piece.clone(),
|
piece,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -129,8 +129,9 @@ impl PersistentCacheTask {
|
||||||
let ttl = Duration::try_from(request.ttl.ok_or(Error::UnexpectedResponse)?)
|
let ttl = Duration::try_from(request.ttl.ok_or(Error::UnexpectedResponse)?)
|
||||||
.or_err(ErrorType::ParseError)?;
|
.or_err(ErrorType::ParseError)?;
|
||||||
|
|
||||||
// Get the content length of the file.
|
// Get the content length of the file asynchronously.
|
||||||
let content_length = std::fs::metadata(path.as_path())
|
let content_length = tokio::fs::metadata(path.as_path())
|
||||||
|
.await
|
||||||
.inspect_err(|err| {
|
.inspect_err(|err| {
|
||||||
error!("get file metadata error: {}", err);
|
error!("get file metadata error: {}", err);
|
||||||
})?
|
})?
|
||||||
|
|
@ -150,8 +151,7 @@ impl PersistentCacheTask {
|
||||||
};
|
};
|
||||||
|
|
||||||
// Notify the scheduler that the persistent cache task is started.
|
// Notify the scheduler that the persistent cache task is started.
|
||||||
match self
|
self.scheduler_client
|
||||||
.scheduler_client
|
|
||||||
.upload_persistent_cache_task_started(UploadPersistentCacheTaskStartedRequest {
|
.upload_persistent_cache_task_started(UploadPersistentCacheTaskStartedRequest {
|
||||||
host_id: host_id.to_string(),
|
host_id: host_id.to_string(),
|
||||||
task_id: task_id.to_string(),
|
task_id: task_id.to_string(),
|
||||||
|
|
@ -167,13 +167,7 @@ impl PersistentCacheTask {
|
||||||
ttl: request.ttl,
|
ttl: request.ttl,
|
||||||
})
|
})
|
||||||
.await
|
.await
|
||||||
{
|
.inspect_err(|err| error!("upload persistent cache task started: {}", err))?;
|
||||||
Ok(_) => {}
|
|
||||||
Err(err) => {
|
|
||||||
error!("upload persistent cache task started: {}", err);
|
|
||||||
return Err(err);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check if the storage has enough space to store the persistent cache task.
|
// Check if the storage has enough space to store the persistent cache task.
|
||||||
let has_enough_space = self.storage.has_enough_space(content_length)?;
|
let has_enough_space = self.storage.has_enough_space(content_length)?;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue