Skip to content

Commit fb264d0

Browse files
authored
Merge pull request #7459 from Turbo87/worker-restart
bin/background-worker: Simplify restart behavior
2 parents 5cc709b + 09b1440 commit fb264d0

File tree

1 file changed

+11
-23
lines changed

1 file changed

+11
-23
lines changed

src/bin/background-worker.rs

Lines changed: 11 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -85,35 +85,23 @@ fn main() -> anyhow::Result<()> {
8585

8686
let environment = Arc::new(environment);
8787

88-
let build_runner = || {
89-
let connection_pool = r2d2::Pool::builder()
90-
.max_size(10)
91-
.min_idle(Some(0))
92-
.build_unchecked(ConnectionManager::new(&db_url));
88+
let connection_pool = r2d2::Pool::builder()
89+
.max_size(10)
90+
.min_idle(Some(0))
91+
.build_unchecked(ConnectionManager::new(&db_url));
9392

94-
let connection_pool = DieselPool::new_background_worker(connection_pool);
93+
let connection_pool = DieselPool::new_background_worker(connection_pool);
9594

96-
Runner::new(connection_pool, environment.clone())
97-
.num_workers(5)
98-
.job_start_timeout(Duration::from_secs(job_start_timeout))
99-
.register_crates_io_job_types()
100-
};
101-
102-
let mut runner = build_runner();
95+
let runner = Runner::new(connection_pool, environment.clone())
96+
.num_workers(5)
97+
.job_start_timeout(Duration::from_secs(job_start_timeout))
98+
.register_crates_io_job_types();
10399

104100
info!("Runner booted, running jobs");
105101

106-
let mut failure_count = 0;
107-
108102
loop {
109-
if let Err(e) = runner.run_all_pending_jobs() {
110-
failure_count += 1;
111-
if failure_count < 5 {
112-
warn!(?failure_count, err = ?e, "Error running jobs -- retrying");
113-
runner = build_runner();
114-
} else {
115-
panic!("Failed to begin running jobs 5 times. Restarting the process");
116-
}
103+
if let Err(err) = runner.run_all_pending_jobs() {
104+
warn!(%err, "Failed to run background jobs");
117105
}
118106
sleep(Duration::from_secs(1));
119107
}

0 commit comments

Comments
 (0)