Initial stabilization #1
1 changed files with 37 additions and 1 deletions
fix: commit cache
commit
c685a1db3e
38
src/lib.rs
38
src/lib.rs
|
|
@ -85,10 +85,14 @@ impl Client {
|
|||
}
|
||||
|
||||
pub fn save_cache(&self, key: &CacheKey, cache: Vec<u8>) -> Result<()> {
|
||||
let cache_id = self.reserve(key, cache.len()).context("reserving cache")?;
|
||||
let cache_len = cache.len();
|
||||
let cache_id = self.reserve(key, cache_len).context("reserving cache")?;
|
||||
|
||||
self.save(cache_id, cache).context("saving the cache")?;
|
||||
|
||||
self.commit_cache(cache_id, cache_len)
|
||||
.context("committing the cache")?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
|
@ -169,6 +173,38 @@ impl Client {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
fn commit_cache(&self, id: CacheId, cache_size: usize) -> Result<()> {
|
||||
let uri = format!("{}_apis/artifactcache/caches/{}", self.base_url, id.0);
|
||||
let request = Request::builder()
|
||||
.uri(uri)
|
||||
.method(Method::POST)
|
||||
.body(
|
||||
serde_json::json! {{
|
||||
"size": cache_size,
|
||||
}}
|
||||
.to_string(),
|
||||
)
|
||||
.context("building the request")?;
|
||||
let mut response = self
|
||||
.http_client
|
||||
.send(request)
|
||||
.context("sending the request")?;
|
||||
let status = response.status();
|
||||
if status != StatusCode::OK {
|
||||
let mut body = Vec::with_capacity(100);
|
||||
response
|
||||
.body_mut()
|
||||
.read_to_end(&mut body)
|
||||
.context("reading response body")?;
|
||||
bail!(
|
||||
"Failed reserving a cache (status {status}): {:?}",
|
||||
String::from_utf8_lossy(&body)
|
||||
);
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn load_cache(&self, key: &CacheKey) -> Result<Option<Box<[u8]>>> {
|
||||
let Some(cache_location) = self.get_cache_entry(key).context("getting cache entry")? else {
|
||||
// cache miss
|
||||
|
|
|
|||
Loading…
Reference in a new issue