Skip to content

Commit f5628c8

Browse files
authored
chore(pegboard): allow configuring reschedule_backoff_max_exponent (#3370)
* fix(next-js): auto shut down runners when source code updates * chore(pegboard): allow configuring reschedule_backoff_max_exponent
1 parent ce0f835 commit f5628c8

File tree

3 files changed

+20
-2
lines changed
  • engine/packages
  • rivetkit-typescript/packages/rivetkit/src/engine-process

3 files changed

+20
-2
lines changed

engine/packages/config/src/config/pegboard.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@ pub struct Pegboard {
2929
///
3030
/// **Experimental**
3131
pub retry_reset_duration: Option<i64>,
32+
/// Maximum exponent for the reschedule backoff calculation.
33+
///
34+
/// This controls the maximum backoff duration when rescheduling actors.
35+
///
36+
/// **Experimental**
37+
pub reschedule_backoff_max_exponent: Option<usize>,
3238
}
3339

3440
impl Pegboard {
@@ -47,4 +53,8 @@ impl Pegboard {
4753
pub fn retry_reset_duration(&self) -> i64 {
4854
self.retry_reset_duration.unwrap_or(10 * 60 * 1000)
4955
}
56+
57+
pub fn reschedule_backoff_max_exponent(&self) -> usize {
58+
self.reschedule_backoff_max_exponent.unwrap_or(8)
59+
}
5060
}

engine/packages/pegboard/src/workflows/actor/runtime.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -619,6 +619,7 @@ pub async fn reschedule_actor(
619619
let mut backoff = reschedule_backoff(
620620
state.reschedule_state.retry_count,
621621
ctx.config().pegboard().base_retry_timeout(),
622+
ctx.config().pegboard().reschedule_backoff_max_exponent(),
622623
);
623624

624625
let (now, reset) = ctx
@@ -736,6 +737,7 @@ async fn compare_retry(ctx: &ActivityCtx, input: &CompareRetryInput) -> Result<(
736737
let backoff = reschedule_backoff(
737738
input.retry_count,
738739
ctx.config().pegboard().base_retry_timeout(),
740+
ctx.config().pegboard().reschedule_backoff_max_exponent(),
739741
);
740742
state.reschedule_ts = Some(now + i64::try_from(backoff.current_duration())?);
741743
}
@@ -815,6 +817,10 @@ pub async fn set_complete(ctx: &ActivityCtx, input: &SetCompleteInput) -> Result
815817
Ok(())
816818
}
817819

818-
fn reschedule_backoff(retry_count: usize, base_retry_timeout: usize) -> util::backoff::Backoff {
819-
util::backoff::Backoff::new_at(8, None, base_retry_timeout, 500, retry_count)
820+
fn reschedule_backoff(
821+
retry_count: usize,
822+
base_retry_timeout: usize,
823+
max_exponent: usize,
824+
) -> util::backoff::Backoff {
825+
util::backoff::Backoff::new_at(max_exponent, None, base_retry_timeout, 500, retry_count)
820826
}

rivetkit-typescript/packages/rivetkit/src/engine-process/mod.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@ export async function ensureEngineProcess(
9797
// order to account for this.
9898
RIVET__PEGBOARD__RETRY_RESET_DURATION: "100",
9999
RIVET__PEGBOARD__BASE_RETRY_TIMEOUT: "100",
100+
// Set max exponent to 1 to have a maximum of base_retry_timeout
101+
RIVET__PEGBOARD__RESCHEDULE_BACKOFF_MAX_EXPONENT: "1",
100102
},
101103
});
102104

0 commit comments

Comments
 (0)