Skip to content

Commit ccccb82

Browse files
authored
Merge pull request #7452 from Turbo87/single-job
worker/swirl/runner: Inline `get_single_job()` fn
2 parents a3da401 + 5dcd71b commit ccccb82

File tree

1 file changed

+13
-19
lines changed

1 file changed

+13
-19
lines changed

src/worker/swirl/runner.rs

+13-19
Original file line numberDiff line numberDiff line change
@@ -108,26 +108,10 @@ impl<Context: Clone + Send + UnwindSafe + 'static> Runner<Context> {
108108
}
109109

110110
fn run_single_job(&self, sender: SyncSender<Event>) {
111+
use diesel::result::Error::RollbackTransaction;
112+
111113
let job_registry = AssertUnwindSafe(self.job_registry.clone());
112114
let environment = self.environment.clone();
113-
self.get_single_job(sender, move |job, state| {
114-
let job_registry = job_registry.read();
115-
let run_task_fn = job_registry
116-
.get(&job.job_type)
117-
.ok_or_else(|| PerformError::from(format!("Unknown job type {}", job.job_type)))?;
118-
119-
run_task_fn(environment, state, job.data)
120-
})
121-
}
122-
123-
fn get_single_job<F>(&self, sender: SyncSender<Event>, f: F)
124-
where
125-
F: FnOnce(storage::BackgroundJob, PerformState<'_>) -> Result<(), PerformError>
126-
+ Send
127-
+ UnwindSafe
128-
+ 'static,
129-
{
130-
use diesel::result::Error::RollbackTransaction;
131115

132116
// The connection may not be `Send` so we need to clone the pool instead
133117
let pool = self.connection_pool.clone();
@@ -175,7 +159,17 @@ impl<Context: Clone + Send + UnwindSafe + 'static> Runner<Context> {
175159
catch_unwind(|| {
176160
// Ensure the whole `AssertUnwindSafe(_)` is moved
177161
let state = state;
178-
f(job, state.0)
162+
163+
let job_registry = job_registry.read();
164+
let run_task_fn =
165+
job_registry.get(&job.job_type).ok_or_else(|| {
166+
PerformError::from(format!(
167+
"Unknown job type {}",
168+
job.job_type
169+
))
170+
})?;
171+
172+
run_task_fn(environment, state.0, job.data)
179173
})
180174
.map_err(|e| try_to_extract_panic_info(&e))
181175
})

0 commit comments

Comments
 (0)