private async Task SplitBatchAndEnqueueMessages(SubmissionJobsToBeDeletedBatch batch, string queueName)
        {
            var endpointInstance = await endpointInstanceFactory.GetEndpointInstance().ConfigureAwait(false);

            foreach (var jobsToBeDeletedModel in batch.JobsToBeDeleted)
            {
                await endpointInstance.Send(queueName, new SubmissionJobsToBeDeletedBatch { JobsToBeDeleted = new[] { jobsToBeDeletedModel } }).ConfigureAwait(false);
            }
        }
 public async Task FundingSourceEventAuditDataCleanUp(SubmissionJobsToBeDeletedBatch batch)
 {
     await AuditDataCleanUp(DeleteFundingSourceEvent, batch, config.FundingSourceAuditDataCleanUpQueue);
 }
 public async Task EarningEventAuditDataCleanUp(SubmissionJobsToBeDeletedBatch batch)
 {
     await AuditDataCleanUp(DeleteEarningEventData, batch, config.EarningAuditDataCleanUpQueue);
 }
        private async Task AuditDataCleanUp(Func <IList <SqlParameter>, string, string, Task> deleteAuditData, SubmissionJobsToBeDeletedBatch batch, string queueName)
        {
            try
            {
                var sqlParameters = batch.JobsToBeDeleted.ToSqlParameters();

                var deleteMethodName = deleteAuditData.Method.Name;

                paymentLogger.LogInfo($"Started {deleteMethodName}");

                var sqlParamName = string.Join(", ", sqlParameters.Select(pn => pn.ParameterName));
                var paramValues  = string.Join(", ", sqlParameters.Select(pn => pn.Value));

                await deleteAuditData(sqlParameters, sqlParamName, paramValues);

                paymentLogger.LogInfo($"Finished {deleteMethodName}");
            }
            catch (Exception e)
            {
                //we have already tried in single batch mode nothing more can be done here
                if (batch.JobsToBeDeleted.Length == 1)
                {
                    paymentLogger.LogWarning($"Error Deleting Audit Data, internal Exception {e}");
                    throw;
                }

                //if SQL TimeOut or Dead-lock and we haven't already tried with single item Mode then try again with Batch Split into single items
                if (e.IsTimeOutException() || e.IsDeadLockException())
                {
                    paymentLogger.LogWarning($"Starting Audit Data Deletion in Single Item mode");

                    await SplitBatchAndEnqueueMessages(batch, queueName);
                }
            }
        }
 public async Task DataLockEventAuditDataCleanUp(SubmissionJobsToBeDeletedBatch batch)
 {
     await AuditDataCleanUp(DeleteDataLockEvent, batch, config.DataLockAuditDataCleanUpQueue);
 }
 public async Task RequiredPaymentEventAuditDataCleanUp(SubmissionJobsToBeDeletedBatch batch)
 {
     await AuditDataCleanUp(DeleteRequiredPaymentEvent, batch, config.RequiredPaymentAuditDataCleanUpQueue);
 }