Skip to content

Commit d5cbf34

Browse files
committed
feat: add lock to avoid race condition on abbs repo
1 parent daeae40 commit d5cbf34

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

server/src/api.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
use crate::{
2-
github::get_crab_github_installation,
3-
github::get_packages_from_pr,
4-
models::{NewJob, NewPipeline, Pipeline, Worker},
5-
DbPool, ALL_ARCH, ARGS,
2+
github::{get_crab_github_installation, get_packages_from_pr}, models::{NewJob, NewPipeline, Pipeline, Worker}, DbPool, ABBS_REPO_LOCK, ALL_ARCH, ARGS
63
};
74
use anyhow::anyhow;
85
use anyhow::Context;
@@ -76,6 +73,7 @@ pub async fn pipeline_new(
7673
git_sha.to_string()
7774
}
7875
None => {
76+
let _lock = ABBS_REPO_LOCK.lock().await;
7977
update_abbs(git_branch, &ARGS.abbs_path)
8078
.await
8179
.context("Failed to update ABBS tree")?;
@@ -198,6 +196,7 @@ pub async fn pipeline_new_pr(
198196
return Err(anyhow!("Failed to create job: Pull request is a fork"));
199197
}
200198

199+
let _lock = ABBS_REPO_LOCK.lock().await;
201200
update_abbs(git_branch, &ARGS.abbs_path)
202201
.await
203202
.context("Failed to update ABBS tree")?;

server/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ pub struct Args {
5151
}
5252

5353
pub static ARGS: Lazy<Args> = Lazy::new(Args::parse);
54+
pub static ABBS_REPO_LOCK: Lazy<tokio::sync::Mutex<()>> = Lazy::new(tokio::sync::Mutex::new);
5455

5556
// follow https://github.com/AOSC-Dev/autobuild3/blob/master/sets/arch_groups/mainline
5657
pub(crate) const ALL_ARCH: &[&str] = &[

0 commit comments

Comments
 (0)