Skip to content
Open
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
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ target
/cache/
/rust.git/
/rust/
/results
/results
/.idea/
37 changes: 33 additions & 4 deletions site/src/job_queue/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use database::{
PendingBenchmarkRequests, Profile, QueuedCommit, Target,
};
use parking_lot::RwLock;
use std::cmp::Reverse;
use std::sync::Arc;
use std::time::Instant;
use tokio::time::{self, Duration, MissedTickBehavior};
Expand Down Expand Up @@ -154,12 +155,11 @@ fn sort_benchmark_requests(pending: PendingBenchmarkRequests) -> Vec<BenchmarkRe
level.sort_unstable_by_key(|bmr| {
(
// Higher priority requests go first
-bmr.priority(),
// PR number takes priority
bmr.pr().unwrap_or(0),
Reverse(bmr.priority()),
// Older requests take priority
bmr.created_at(),
// Order master commits before try commits
if bmr.is_master() { 0 } else { 1 },
bmr.created_at(),
)
});
for c in level {
Expand Down Expand Up @@ -900,6 +900,35 @@ mod tests {
.await;
}

#[tokio::test]
async fn queue_oldest_request_first() {
run_postgres_test(|ctx| async {
ctx.add_collector(CollectorBuilder::default()).await;

ctx.insert_master_request("base", "base2", 1).await;
ctx.insert_try_request(4, 0).await;
ctx.db()
.attach_shas_to_try_benchmark_request(4, "pr4", "base", Utc::now())
.await
.unwrap();
ctx.insert_try_request(2, 0).await;
ctx.db()
.attach_shas_to_try_benchmark_request(2, "pr2", "base", Utc::now())
.await
.unwrap();
ctx.insert_try_request(3, 0).await;
ctx.db()
.attach_shas_to_try_benchmark_request(3, "pr3", "base", Utc::now())
.await
.unwrap();

let queue = build_queue(ctx.db()).await?;
queue_order_matches(&queue, &["base", "pr4", "pr2", "pr3"]);
Ok(ctx)
})
.await;
}

#[tokio::test]
async fn insert_all_jobs() {
run_postgres_test(|mut ctx| async {
Expand Down
Loading