private async Task ProcessMissPendingItem(string missEventId, string[] itemList) { var missAdapter = new Adapters.Oal.dbo_missort_event_newAdapter(); var missPendingPolly = await Policy.Handle <SqlException>(e => e.IsTimeout()) .WaitAndRetryAsync(RetryCount, WaitInterval) .ExecuteAndCaptureAsync(async() => await missAdapter.LoadOneAsync(missEventId)); if (null != missPendingPolly.FinalException) { throw new Exception("Process Miss Pending Polly Error", missPendingPolly.FinalException); } var miss = missPendingPolly.Result; var missItems = new List <Adapters.Oal.dbo_missort_event_new>(); foreach (var item in itemList) { var console = IsConsole(item); var child = miss.Clone(); child.id = GenerateId(34); child.consignment_no = item; child.data_flag = "1"; child.item_type_code = console ? "02" : "01"; missItems.Add(child); } foreach (var item in missItems) { item.date_created_oal_date_field = item.date_created_oal_date_field.ToValidSqlDateTime(); item.date_field = item.date_field.ToValidSqlDateTime(); var pr = Policy.Handle <SqlException>(e => e.IsDeadlockOrTimeout()) .WaitAndRetryAsync(RetryCount, WaitInterval) .ExecuteAndCaptureAsync(() => missAdapter.InsertAsync(item)); var result = await pr; if (result.FinalException != null) { throw result.FinalException; // send to dead letter queue } System.Diagnostics.Debug.Assert(result.Result > 0, "Should be at least 1 row"); } }
public async Task RunAsync(Misses.Domain.Miss miss) { //console_details var consoleList = new List <string>(); if (IsConsole(miss.ConsignmentNo)) { consoleList.Add(miss.ConsignmentNo); } var missEventAdapter = new Adapters.Oal.dbo_missort_event_newAdapter(); var missEventMap = new Integrations.Transforms.RtsMissToOalMissortEventNew(); var parentRow = await missEventMap.TransformAsync(miss); parentRow.id = GenerateId(34); m_missEventRows.Add(parentRow); var consoleItem = await GetItemConsigmentsFromConsoleDetailsAsync(miss.ConsignmentNo); if (null != consoleItem) { var children = consoleItem.Split(new[] { '\t' }, StringSplitOptions.RemoveEmptyEntries); foreach (var item in children) { if (consoleList.Contains(item)) { continue; } ProcessChild(parentRow, item); //2 level var console = IsConsole(item); if (console) { consoleList.Add(item); var childConsole = await GetItemConsigmentsFromConsoleDetailsAsync(item); if (null != childConsole) { var childConsoleItems = childConsole.Split(new[] { '\t' }, StringSplitOptions.RemoveEmptyEntries); foreach (var cc in childConsoleItems) { if (consoleList.Contains(cc)) { continue; } ProcessChild(parentRow, cc); //3 level var anotherConsole = IsConsole(cc); if (anotherConsole) { consoleList.Add(cc); var anotherChildConsole = await GetItemConsigmentsFromConsoleDetailsAsync(cc); if (null != anotherChildConsole) { var anotherChildConsoleItems = anotherChildConsole.Split(new[] { '\t' }, StringSplitOptions.RemoveEmptyEntries); foreach (var ccc in anotherChildConsoleItems) { if (consoleList.Contains(ccc)) { continue; } ProcessChild(parentRow, ccc); } } else { AddPendingItems(parentRow.id, cc); } } } } else { AddPendingItems(parentRow.id, item); } } } } else { AddPendingItems(parentRow.id, miss.ConsignmentNo); } foreach (var item in m_missEventRows) { var pr = Policy.Handle <SqlException>() .WaitAndRetryAsync(5, x => TimeSpan.FromMilliseconds(500 * Math.Pow(2, x))) .ExecuteAndCaptureAsync(() => TrackEvents(missEventAdapter.InsertAsync, item)); var result = await pr; if (result.FinalException != null) { throw result.FinalException; // send to dead letter queue } System.Diagnostics.Debug.Assert(result.Result > 0, "Should be at least 1 row"); } var pendingAdapter = new Adapters.Oal.dbo_event_pending_consoleAdapter(); foreach (var item in m_missEventPendingConsoleRows) { var pr = Policy.Handle <SqlException>() .WaitAndRetryAsync(5, x => TimeSpan.FromMilliseconds(500 * Math.Pow(2, x))) .ExecuteAndCaptureAsync(() => TrackEvents(pendingAdapter.InsertAsync, item)); var result = await pr; if (result.FinalException != null) { throw result.FinalException; // send to dead letter queue } System.Diagnostics.Debug.Assert(result.Result > 0, "Should be at least 1 row"); } }