Skip to content

Commit 17624cf

Browse files
Delay posting bors try comment by one second
1 parent b6f50cf commit 17624cf

File tree

3 files changed

+48
-40
lines changed

3 files changed

+48
-40
lines changed

site/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ env_logger = "0.7"
99
anyhow = "1"
1010
thiserror = "1"
1111
futures = "0.3"
12-
tokio = { version = "0.2", features = ["macros"] }
12+
tokio = { version = "0.2", features = ["macros", "time"] }
1313
log = "0.4"
1414
serde = "1"
1515
serde_derive = "1"

site/src/github.rs

Lines changed: 45 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use serde::Deserialize;
66

77
use regex::Regex;
88
use reqwest::header::USER_AGENT;
9+
use std::{sync::Arc, time::Duration};
910

1011
lazy_static::lazy_static! {
1112
static ref BODY_TRY_COMMIT: Regex =
@@ -36,11 +37,11 @@ async fn get_authorized_users() -> ServerResult<Vec<usize>> {
3637

3738
pub async fn handle_github(
3839
request: github::Request,
39-
data: &InputData,
40+
data: Arc<InputData>,
4041
) -> ServerResult<github::Response> {
4142
if request.comment.body.contains(" homu: ") {
4243
if let Some(sha) = handle_homu_res(&request).await {
43-
return enqueue_sha(request, data, sha).await;
44+
return enqueue_sha(request, &data, sha).await;
4445
}
4546
}
4647

@@ -83,7 +84,7 @@ pub async fn handle_github(
8384
let conn = data.conn().await;
8485
conn.queue_pr(request.issue.number).await;
8586
}
86-
let f = enqueue_sha(request, data, commit.to_owned());
87+
let f = enqueue_sha(request, &data, commit.to_owned());
8788
return f.await;
8889
}
8990
}
@@ -98,7 +99,7 @@ pub async fn handle_github(
9899
let client = reqwest::Client::new();
99100
pr_and_try_for_rollup(
100101
&client,
101-
&data,
102+
data.clone(),
102103
&request.issue.repository_url,
103104
&rollup_merge,
104105
&request.comment.html_url,
@@ -121,7 +122,7 @@ pub async fn handle_github(
121122
// between us updating the commit and merging things.
122123
let client = reqwest::Client::new();
123124
let branch =
124-
branch_for_rollup(&client, data, &request.issue.repository_url, rollup_merge)
125+
branch_for_rollup(&client, &data, &request.issue.repository_url, rollup_merge)
125126
.await
126127
.map_err(|e| e.to_string())?;
127128
post_comment(
@@ -139,7 +140,7 @@ pub async fn handle_github(
139140
// Returns the PR number
140141
async fn pr_and_try_for_rollup(
141142
client: &reqwest::Client,
142-
data: &InputData,
143+
data: Arc<InputData>,
143144
repository_url: &str,
144145
rollup_merge_sha: &str,
145146
origin_url: &str,
@@ -149,11 +150,11 @@ async fn pr_and_try_for_rollup(
149150
repository_url,
150151
rollup_merge_sha
151152
);
152-
let branch = branch_for_rollup(client, data, repository_url, rollup_merge_sha).await?;
153+
let branch = branch_for_rollup(client, &data, repository_url, rollup_merge_sha).await?;
153154

154155
let pr = create_pr(
155156
client,
156-
data,
157+
&data,
157158
repository_url,
158159
&format!(
159160
"[DO NOT MERGE] perf-test for #{}",
@@ -165,42 +166,49 @@ async fn pr_and_try_for_rollup(
165166
"This is an automatically generated pull request (from [here]({})) to \
166167
run perf tests for #{} which merged in a rollup.
167168
168-
r? @ghost",
169+
r? @ghost",
169170
origin_url, branch.rolled_up_pr_number
170171
),
171172
)
172173
.await
173174
.context("Created PR")?;
174175

175-
// This provides the master SHA so that we can check that we only queue
176-
// an appropriate try build. If there's ever a race condition, i.e.,
177-
// master was pushed while this command was running, the user will have to
178-
// take manual action to detect it.
179-
//
180-
// Eventually we'll want to handle this automatically, but that's a ways
181-
// off: we'd need to store the state in the database and handle the try
182-
// build starting and generally that's a lot of work for not too much gain.
183-
post_comment(
184-
&data.config,
185-
pr.number,
186-
&format!(
187-
"@bors try @rust-timer queue\n
188-
The try commit's (master) parent should be {master}. If it isn't, \
189-
then please:
190-
191-
* Stop this try build (`try-`).
192-
* Run `@rust-timer update-pr-for {merge}`.
193-
* Rerun `bors try`.
194-
195-
You do not need to reinvoke the queue command as long as the perf \
196-
build hasn't yet started.",
197-
master = branch.master_base_sha,
198-
merge = rollup_merge_sha,
199-
),
200-
)
201-
.await;
176+
let pr_number = pr.number;
177+
let rollup_merge_sha = rollup_merge_sha.to_owned();
178+
tokio::task::spawn(async move {
179+
// Give github time to create the merge commit reference
180+
tokio::time::delay_for(Duration::from_secs(1)).await;
181+
// This provides the master SHA so that we can check that we only queue
182+
// an appropriate try build. If there's ever a race condition, i.e.,
183+
// master was pushed while this command was running, the user will have to
184+
// take manual action to detect it.
185+
//
186+
// Eventually we'll want to handle this automatically, but that's a ways
187+
// off: we'd need to store the state in the database and handle the try
188+
// build starting and generally that's a lot of work for not too much gain.
189+
post_comment(
190+
&data.config,
191+
pr.number,
192+
&format!(
193+
"@bors try @rust-timer queue
194+
195+
The try commit's (master) parent should be {master}. If it isn't, \
196+
then please:
197+
198+
* Stop this try build (`try-`).
199+
* Run `@rust-timer update-pr-for {merge}`.
200+
* Rerun `bors try`.
201+
202+
You do not need to reinvoke the queue command as long as the perf \
203+
build hasn't yet started.",
204+
master = branch.master_base_sha,
205+
merge = rollup_merge_sha,
206+
),
207+
)
208+
.await;
209+
});
202210

203-
Ok(pr.number)
211+
Ok(pr_number)
204212
}
205213

206214
struct RollupBranch {

site/src/server.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -572,7 +572,7 @@ impl DateData {
572572

573573
pub async fn handle_github(
574574
request: github::Request,
575-
data: &InputData,
575+
data: Arc<InputData>,
576576
) -> ServerResult<github::Response> {
577577
crate::github::handle_github(request, data).await
578578
}
@@ -1078,7 +1078,7 @@ async fn serve_req(ctx: Arc<Server>, req: Request) -> Result<Response, ServerErr
10781078
.unwrap());
10791079
}
10801080
Ok(to_response(
1081-
handle_github(body!(parse_body(&body)), &data).await,
1081+
handle_github(body!(parse_body(&body)), data.clone()).await,
10821082
))
10831083
} else if p == "/perf/self-profile" {
10841084
Ok(to_response(

0 commit comments

Comments
 (0)