Make commit events atomic
This moves the Event that triggers the addition of the commit to the
store inside the transaction. This prevents a commit from being added to
the store if one of the other db events in the transaction fails.
@@ -156,6 +156,7 @@ impl EventHandler for DatabaseEventHandler<diesel::pg::PgConnection> {
.get()
.map_err(|err| EventError(format!("Unable to connect to database: {}", err)))?;
+ conn.build_transaction().run::<_, EventError, _>(|| {
let commit = if let Some(commit) = self
.commit_store
.create_db_commit_from_commit_event(&DbCommitEvent::from(event))
@@ -175,7 +176,6 @@ impl EventHandler for DatabaseEventHandler<diesel::pg::PgConnection> {
trace!("The following operations will be performed: {:#?}", db_ops);
- conn.build_transaction().run::<_, EventError, _>(|| {
match self
.commit_store
.get_commit_by_commit_num(commit.commit_num)
@@ -338,6 +338,7 @@ impl EventHandler for DatabaseEventHandler<diesel::sqlite::SqliteConnection> {
.get()
.map_err(|err| EventError(format!("Unable to connect to database: {}", err)))?;
+ conn.transaction::<_, EventError, _>(|| {
let commit = if let Some(commit) = self
.commit_store
.create_db_commit_from_commit_event(&DbCommitEvent::from(event))
@@ -357,7 +358,6 @@ impl EventHandler for DatabaseEventHandler<diesel::sqlite::SqliteConnection> {
trace!("The following operations will be performed: {:#?}", db_ops);
- conn.transaction::<_, EventError, _>(|| {
match self
.commit_store
.get_commit_by_commit_num(commit.commit_num)
