Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 12 additions & 39 deletions site/src/job_queue/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ async fn create_benchmark_request_master_commits(
ctxt: &SiteCtxt,
conn: &dyn database::pool::Connection,
index: &BenchmarkRequestIndex,
) -> anyhow::Result<bool> {
) -> anyhow::Result<()> {
let now = Utc::now();

let master_commits = ctxt.get_master_commits();
Expand All @@ -44,7 +44,6 @@ async fn create_benchmark_request_master_commits(
.iter()
.filter(|c| now.signed_duration_since(c.time) < chrono::Duration::days(29));

let mut inserted = false;
for master_commit in master_commits {
if !index.contains_tag(&master_commit.sha) && conn.pr_of(&master_commit.sha).await.is_none()
{
Expand All @@ -59,12 +58,10 @@ async fn create_benchmark_request_master_commits(

if let Err(error) = conn.insert_benchmark_request(&benchmark).await {
log::error!("Failed to insert master benchmark request: {error:?}");
} else {
inserted = true;
}
}
}
Ok(inserted)
Ok(())
}

/// Store the latest release commits or do nothing if all of them are
Expand All @@ -73,7 +70,7 @@ async fn create_benchmark_request_master_commits(
async fn create_benchmark_request_releases(
conn: &dyn database::pool::Connection,
index: &BenchmarkRequestIndex,
) -> anyhow::Result<bool> {
) -> anyhow::Result<()> {
let releases: String = reqwest::get("https://static.rust-lang.org/manifests.txt")
.await?
.text()
Expand All @@ -85,20 +82,17 @@ async fn create_benchmark_request_releases(
.filter_map(parse_release_string)
.take(20);

let mut inserted = false;
for (name, commit_date) in releases {
if !index.contains_tag(&name) && conn.artifact_by_name(&name).await.is_none() {
let release_request = BenchmarkRequest::create_release(&name, commit_date);
log::info!("Inserting release benchmark request {release_request:?}");

if let Err(error) = conn.insert_benchmark_request(&release_request).await {
log::error!("Failed to insert release benchmark request: {error}");
} else {
inserted = true;
}
}
}
Ok(inserted)
Ok(())
}

/// Sorts try and master requests that are in the `ArtifactsReady` status and return them in the
Expand Down Expand Up @@ -414,23 +408,18 @@ async fn perform_queue_tick(ctxt: &SiteCtxt) -> anyhow::Result<()> {
return Ok(());
}

let index = ctxt.known_benchmark_requests.load();

let mut requests_inserted = false;
let index = conn
.load_benchmark_request_index()
.await
.context("Failed to load benchmark request index")?;

// Put the master commits into the `benchmark_requests` queue
match create_benchmark_request_master_commits(ctxt, &*conn, &index).await {
Ok(inserted) => requests_inserted |= inserted,
Err(error) => {
log::error!("Could not insert master benchmark requests into the database: {error:?}");
}
if let Err(error) = create_benchmark_request_master_commits(ctxt, &*conn, &index).await {
log::error!("Could not insert master benchmark requests into the database: {error:?}");
}
// Put the releases into the `benchmark_requests` queue
match create_benchmark_request_releases(&*conn, &index).await {
Ok(inserted) => requests_inserted |= inserted,
Err(error) => {
log::error!("Could not insert release benchmark requests into the database: {error:?}");
}
if let Err(error) = create_benchmark_request_releases(&*conn, &index).await {
log::error!("Could not insert release benchmark requests into the database: {error:?}");
}

let mut completed_benchmarks = vec![];
Expand All @@ -450,22 +439,6 @@ async fn perform_queue_tick(ctxt: &SiteCtxt) -> anyhow::Result<()> {
);
}

// If some change happened, reload the benchmark request index
if requests_inserted {
match conn
.load_benchmark_request_index()
.await
.context("Failed to load benchmark request index")
{
Ok(index) => {
ctxt.known_benchmark_requests.store(Arc::new(index));
}
Err(error) => {
result = combine_result(result, Err(error));
}
};
}

// Propagate the error
result
}
Expand Down
6 changes: 1 addition & 5 deletions site/src/load.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ use serde::{Deserialize, Serialize};
use crate::self_profile::SelfProfileCache;
use collector::compile::benchmark::category::Category;
use collector::{Bound, MasterCommit};
use database::Pool;
pub use database::{ArtifactId, Benchmark, Commit};
use database::{BenchmarkRequestIndex, Pool};
use database::{CommitType, Date};

#[derive(Debug, PartialEq, Eq, Clone, Serialize, Deserialize)]
Expand Down Expand Up @@ -128,8 +128,6 @@ pub struct SiteCtxt {
pub landing_page: ArcSwap<Option<Arc<crate::api::graphs::Response>>>,
/// Index of various common queries
pub index: ArcSwap<database::Index>,
/// Index of all benchmark requests that we have in the DB
pub known_benchmark_requests: ArcSwap<BenchmarkRequestIndex>,
/// Cached master-branch Rust commits
pub master_commits: Arc<ArcSwap<MasterCommitCache>>, // outer Arc enables mutation in background task
/// Cache for self profile data
Expand Down Expand Up @@ -162,7 +160,6 @@ impl SiteCtxt {

let mut conn = pool.connection().await;
let index = database::Index::load(&mut *conn).await;
let benchmark_request_index = conn.load_benchmark_request_index().await?;

let config = if let Ok(s) = fs::read_to_string("site-config.toml") {
toml::from_str(&s)?
Expand All @@ -180,7 +177,6 @@ impl SiteCtxt {
Ok(Self {
config,
index: ArcSwap::new(Arc::new(index)),
known_benchmark_requests: ArcSwap::new(Arc::new(benchmark_request_index)),
master_commits: Arc::new(ArcSwap::new(Arc::new(master_commits))),
pool,
landing_page: ArcSwap::new(Arc::new(None)),
Expand Down
Loading