Skip to content

Commit 2ecf243

Browse files
committed
Get DB from the context if possible
1 parent de42aaf commit 2ecf243

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

src/db.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -235,8 +235,9 @@ pub async fn schedule_job(
235235
Ok(())
236236
}
237237

238-
pub async fn run_scheduled_jobs(ctx: &Context, db: &DbClient) -> anyhow::Result<()> {
239-
let jobs = get_jobs_to_execute(&db).await.unwrap();
238+
pub async fn run_scheduled_jobs(ctx: &Context) -> anyhow::Result<()> {
239+
let db = &ctx.db.get().await;
240+
let jobs = get_jobs_to_execute(&db).await?;
240241
tracing::trace!("jobs to execute: {:#?}", jobs);
241242

242243
for job in jobs.iter() {

src/main.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -401,13 +401,12 @@ fn spawn_job_runner(ctx: Arc<Context>) {
401401
loop {
402402
let ctx = ctx.clone();
403403
let res = task::spawn(async move {
404-
let pool = db::ClientPool::new();
405404
let mut interval =
406405
time::interval(time::Duration::from_secs(JOB_PROCESSING_CADENCE_IN_SECS));
407406

408407
loop {
409408
interval.tick().await;
410-
db::run_scheduled_jobs(&ctx, &*pool.get().await)
409+
db::run_scheduled_jobs(&ctx)
411410
.await
412411
.context("run database scheduled jobs")
413412
.unwrap();

0 commit comments

Comments
 (0)