@@ -85,10 +85,10 @@ pub async fn lock(build_id: i64) -> laravel::Result<()> {
8585/// [`HEARTBEAT_SECONDS`]; a run that ends releases it, and one whose worker was killed (a deploy, an out-of-memory
8686/// kill) stops renewing it, so the build is free again within this time and the sweep runs it again. (A lock held for a
8787/// whole run's timeout kept a killed run's build stuck for 20 minutes.)
88- pub const HOLD_SECONDS : i64 = 120 ;
88+ pub const HOLD_SECONDS : i64 = 60 ;
8989
9090/// How often a run renews its hold on the build.
91- const HEARTBEAT_SECONDS : u64 = 30 ;
91+ const HEARTBEAT_SECONDS : u64 = 15 ;
9292
9393/// How long the note to run a build again lasts ([`run`]): longer than any run.
9494const AGAIN_MINUTES : i64 = 20 ;
@@ -127,6 +127,17 @@ pub struct Hold {
127127 pub heartbeat : std:: time:: Duration ,
128128}
129129
130+ /// The name of a build's processing lock ([`exclusive`]).
131+ fn processing_lock_name ( build_id : i64 ) -> String {
132+ format ! ( "builds.process:{build_id}" )
133+ }
134+
135+ /// A build's processing lock, to see whether a run holds it.
136+ fn processing_lock ( build_id : i64 ) -> laravel:: Result < laravel:: cache:: Lock > {
137+ use laravel:: time:: ToSpan ;
138+ laravel:: cache:: lock ( & processing_lock_name ( build_id) , 1 . seconds ( ) )
139+ }
140+
130141/// [`exclusive`] with its timing given.
131142///
132143/// # Errors
@@ -137,7 +148,7 @@ where
137148 Fut : std:: future:: Future < Output = laravel:: Result < T > > ,
138149{
139150 use laravel:: time:: ToSpan ;
140- let lock = laravel:: cache:: lock ( & format ! ( "builds.process:{ build_id}" ) , hold. seconds . seconds ( ) ) ?;
151+ let lock = laravel:: cache:: lock ( & processing_lock_name ( build_id) , hold. seconds . seconds ( ) ) ?;
141152 let out = lock
142153 . block ( wait_seconds. seconds ( ) )
143154 . get ( || async {
@@ -1177,8 +1188,10 @@ pub async fn compare_now(
11771188pub const LOCAL_IDLE : & str = "Closed without review: a local build, idle for 7 days." ;
11781189/// How long a local build waits for its own person's review before it leaves the waiting lists.
11791190pub const LOCAL_IDLE_DAYS : i32 = 7 ;
1180- /// A build still processing this long after its last change is run again: its job's dispatch may have been lost.
1181- pub const RESTART_AFTER_MINUTES : i32 = 10 ;
1191+ /// A build still processing this long after its last change, with no run holding it, is run again: its job's dispatch
1192+ /// was lost, or its run's worker was killed (a deploy) and the job's next attempt found the dead run's hold still there
1193+ /// and left it a note it never read (4 Dec 2026, build 1069). A live run renews its hold, so it's never run twice.
1194+ pub const RESTART_AFTER_MINUTES : i32 = 3 ;
11821195/// A build still processing this long after it was finalized fails: something keeps it from finishing.
11831196pub const GIVE_UP_AFTER_HOURS : i32 = 6 ;
11841197/// The error on a build that never finished processing.
@@ -1233,8 +1246,13 @@ pub async fn sweep() -> laravel::Result<Swept> {
12331246 for id in idle. iter ( ) . chain ( & stuck) {
12341247 crate :: events:: BuildChanged { build_id : * id } . dispatch ( ) . await ?;
12351248 }
1236- for id in & restart {
1237- crate :: jobs:: process_build:: ProcessBuild { build_id : * id } . dispatch ( ) . await ?;
1249+ let mut restarted = 0 ;
1250+ for id in restart {
1251+ if processing_lock ( id) ?. is_locked ( ) . await ? {
1252+ continue ;
1253+ }
1254+ crate :: jobs:: process_build:: ProcessBuild { build_id : id } . dispatch ( ) . await ?;
1255+ restarted += 1 ;
12381256 }
1239- Ok ( Swept { expired, idle_local_closed : idle. len ( ) , restarted : restart . len ( ) , stuck_failed : stuck. len ( ) } )
1257+ Ok ( Swept { expired, idle_local_closed : idle. len ( ) , restarted, stuck_failed : stuck. len ( ) } )
12401258}
0 commit comments