Skip to content

Commit

Permalink
Adding dependents/dependencies to persistence
Browse files Browse the repository at this point in the history
  • Loading branch information
NicholasLYang committed Dec 9, 2024
1 parent 727862d commit 0c0b090
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 19 deletions.
21 changes: 18 additions & 3 deletions crates/turborepo-api-client/src/spaces.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use std::collections::HashSet;
use std::{backtrace::Backtrace, collections::HashSet, str::FromStr};

use async_graphql::{Enum, SimpleObject};
use chrono::{DateTime, Local};
use reqwest::Method;
use serde::Serialize;
use serde::{Deserialize, Serialize};
use turbopath::AnchoredSystemPath;
use turborepo_vercel_api::SpaceRun;

Expand Down Expand Up @@ -48,14 +48,29 @@ pub enum CacheStatus {
Miss,
}

impl FromStr for CacheStatus {
type Err = Error;

fn from_str(s: &str) -> Result<Self, Self::Err> {
match s {
"HIT" => Ok(Self::Hit),
"MISS" => Ok(Self::Miss),
_ => Err(Error::UnknownCachingStatus(
s.to_string(),
Backtrace::capture(),
)),
}
}
}

#[derive(Debug, Serialize, Copy, Clone, PartialEq, Eq, Enum)]
#[serde(rename_all = "UPPERCASE")]
pub enum CacheSource {
Local,
Remote,
}

#[derive(Debug, Serialize, SimpleObject, PartialEq, Eq, Hash)]
#[derive(Debug, Deserialize, Serialize, SimpleObject, PartialEq, Eq, Hash)]
pub struct TaskId {
pub package: String,
pub task: String,
Expand Down
52 changes: 36 additions & 16 deletions crates/turborepo-db/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,22 +99,42 @@ impl DatabaseHandle {
)
.bind(run_id.to_string());
Ok(query
.map(|row: SqliteRow| SpaceTaskSummary {
key: row.get("key"),
name: row.get("name"),
workspace: row.get("workspace"),
hash: row.get("hash"),
start_time: row.get("start_time"),
end_time: row.get("end_time"),
cache: SpacesCacheStatus {
status: row.get("cache_status"),
source: None,
time_saved: row.get("time_saved"),
},
exit_code: row.get("exit_code"),
dependencies: row.get("dependencies"),
dependents: row.get("dependents"),
logs: row.get("logs"),
.try_map(|row: SqliteRow| {
let dependencies: Option<String> = row.get("dependencies");
let dependents: Option<String> = row.get("dependents");
let cache_status: String = row.get("cache_status");

let dependencies = dependencies
.as_deref()
.map(serde_json::from_str)
.transpose()
.map_err(|err| sqlx::Error::Decode(Box::new(err)))?;

let dependents = dependents
.as_deref()
.map(serde_json::from_str)
.transpose()
.map_err(|err| sqlx::Error::Decode(Box::new(err)))?;

Ok(SpaceTaskSummary {
key: row.get("key"),
name: row.get("name"),
workspace: row.get("workspace"),
hash: row.get("hash"),
start_time: row.get("start_time"),
end_time: row.get("end_time"),
cache: SpacesCacheStatus {
status: cache_status
.parse()
.map_err(|err| sqlx::Error::Decode(Box::new(err)))?,
source: None,
time_saved: row.get("time_saved"),
},
exit_code: row.get("exit_code"),
dependencies,
dependents,
logs: row.get("logs"),
})
})
.fetch_all(&self.pool)
.await?)
Expand Down

0 comments on commit 0c0b090

Please sign in to comment.