Skip to content

Commit

Permalink
added try-catch on the Close function to add a log when the SourceRea…
Browse files Browse the repository at this point in the history
…der does UpdateExportedOrdersInDb. Added Transaction-logic for UpdateExportedOrdersInDb function, so we now do a RollBack if an Exception is made on the Commit to database.
  • Loading branch information
MatthiasSort committed Nov 8, 2023
1 parent a2a7394 commit 7846f78
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<Version>10.0.7</Version>
<Version>10.0.8</Version>
<AssemblyVersion>1.0.0.0</AssemblyVersion>
<Title>Order Provider</Title>
<Description>Order Provider</Description>
Expand Down
12 changes: 10 additions & 2 deletions src/OrderProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,16 @@ public override void LoadSettings(Job job)
public new void Close()
{
if (job != null && job.Result == JobResult.Completed)
OrderSourceReader.UpdateExportedOrdersInDb(OrderStateAfterExport, connection);

{
try
{
OrderSourceReader.UpdateExportedOrdersInDb(OrderStateAfterExport, connection);
}
catch (Exception ex)
{
Logger?.Warn(ex.Message);
}
}
Connection.Close();
}

Expand Down
6 changes: 5 additions & 1 deletion src/OrderSourceReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,8 @@ public static void UpdateExportedOrdersInDb(string orderStateIDAfterExport, SqlC
SqlCommand command = new SqlCommand { Connection = connection };
try
{
command.Transaction = connection.BeginTransaction("OrderProviderTransaction");

if (connection.State.ToString() != "Open")
connection.Open();

Expand Down Expand Up @@ -185,10 +187,12 @@ public static void UpdateExportedOrdersInDb(string orderStateIDAfterExport, SqlC
command.ExecuteNonQuery();
ClearOrderCache(_ordersToExport);
}
command.Transaction.Commit();
}
catch (Exception ex)
{
throw new Exception(string.Format("Exception message: {0} Sql query: {1}", ex.Message, command.CommandText), ex);
command.Transaction.Rollback();
throw new Exception(string.Format("A rollback is made as exception is made with message: {0} Sql query: {1}", ex.Message, command.CommandText), ex);
}
finally
{
Expand Down

0 comments on commit 7846f78

Please sign in to comment.