Skip to content

Commit

Permalink
lib: handle closing PRs as a background task
Browse files Browse the repository at this point in the history
We can end up with a lot of references to remove when closing a PR.  We
don't want to do this with a mass number of individual API requests
because that could blow through our quota.  However, when using GraphQL,
it still takes over 10s to delete just 50 references.  Given that, we
have no real choice but to run this task in the background and report
success to GitHub before it decides to hang up on us.
  • Loading branch information
jsbronder committed Feb 6, 2024
1 parent 488f43c commit 2dbbefe
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ impl State {
repo = repo_client.full_name(),
pr = payload.number
);
async move { on_pull_request(repo_client, payload).await }
async move { on_pull_request(repo_client, self.tasks.clone(), payload).await }
.instrument(span)
.await?;
}
Expand Down Expand Up @@ -104,6 +104,7 @@ impl State {

async fn on_pull_request(
repo_client: RepositoryClient,
tasks: TaskTracker,
payload: Box<PullRequestWebhookEventPayload>,
) -> Result<(), ChetterError> {
match payload.action {
Expand Down Expand Up @@ -137,9 +138,15 @@ async fn on_pull_request(
}
PullRequestWebhookEventAction::Closed => {
let sub_span = tracing::span!(tracing::Level::INFO, "close");
async move { close_pr(repo_client, payload.number).await }
.instrument(sub_span)
.await

// We can end up with a lot of references to remove. We can do that in a single API
// call using GraphQL, but it still takes over 10s to delete just 50 references.
// Given that, we have no real choice but to run this task in the background and
// report success to GitHub before it decides to hang up on us.
tasks.spawn(
async move { close_pr(repo_client, payload.number).await }.instrument(sub_span),
);
Ok(())
}

_ => {
Expand Down

0 comments on commit 2dbbefe

Please sign in to comment.