Skip to content
This repository has been archived by the owner on Feb 8, 2024. It is now read-only.

Commit

Permalink
take ownership of batch in commit
Browse files Browse the repository at this point in the history
  • Loading branch information
bretthoerner committed Feb 6, 2024
1 parent b8411bd commit 772733c
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions hook-common/src/pgqueue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use std::{str::FromStr, sync::Arc};
use async_trait::async_trait;
use chrono;
use serde;
use sqlx::postgres::any::AnyConnectionBackend;
use sqlx::postgres::{PgConnectOptions, PgPool, PgPoolOptions};
use thiserror::Error;
use tokio::sync::Mutex;
Expand Down Expand Up @@ -333,14 +334,18 @@ pub struct PgTransactionBatch<'c, J, M> {
}

impl<'c, J, M> PgTransactionBatch<'_, J, M> {
pub async fn commit(&mut self) -> PgQueueResult<()> {
pub async fn commit(self) -> PgQueueResult<()> {
let mut txn_guard = self.shared_txn.lock().await;

let txn = txn_guard.take().unwrap();
txn.commit().await.map_err(|e| PgQueueError::QueryError {
command: "COMMIT".to_owned(),
error: e,
})?;
txn_guard
.as_deref_mut()
.ok_or(PgQueueError::TransactionAlreadyClosedError)?
.commit()
.await
.map_err(|e| PgQueueError::QueryError {
command: "COMMIT".to_owned(),
error: e,
})?;

Ok(())
}
Expand Down

0 comments on commit 772733c

Please sign in to comment.