public async Task SetManualSuspicionLevelsAsync(ManualSuspicionLevels manualSuspicionLevels) { using (var ts = new TransactionScope(TransactionScopeOption.Required, TimeSpan.FromSeconds(30), TransactionScopeAsyncFlowOption.Enabled)) { db.AddOrUpdate(manualSuspicionLevels, p => p.TaskId == manualSuspicionLevels.TaskId); await db.SaveChangesAsync().ConfigureAwait(false); ts.Complete(); } }
public async Task SaveTaskStatisticsParametersAsync(TaskStatisticsParameters parameters) { using (var transaction = db.Database.BeginTransaction()) { db.AddOrUpdate(parameters, p => p.TaskId == parameters.TaskId); await db.SaveChangesAsync(); transaction.Commit(); } }
public async Task SaveMostSimilarSubmissionAsync(MostSimilarSubmission mostSimilarSubmission) { using (var ts = new TransactionScope(TransactionScopeOption.Required, TimeSpan.FromSeconds(30), TransactionScopeAsyncFlowOption.Enabled)) { db.AddOrUpdate(mostSimilarSubmission, p => p.SubmissionId == mostSimilarSubmission.SubmissionId); await db.SaveChangesAsync().ConfigureAwait(false); ts.Complete(); } }
private async Task TrySaveTaskStatisticsParametersAsync(TaskStatisticsParameters parameters) { using (var transaction = await db.Database.BeginTransactionAsync(IsolationLevel.Serializable).ConfigureAwait(false)) { db.AddOrUpdate(parameters, p => p.TaskId == parameters.TaskId); await db.SaveChangesAsync().ConfigureAwait(false); transaction.Commit(); } }
private async Task TrySaveTaskStatisticsParametersAsync(TaskStatisticsParameters parameters) { using (var ts = new TransactionScope(TransactionScopeOption.Required, TimeSpan.FromSeconds(30), TransactionScopeAsyncFlowOption.Enabled)) { db.AddOrUpdate(parameters, p => p.TaskId == parameters.TaskId); await db.SaveChangesAsync().ConfigureAwait(false); ts.Complete(); } }
public async Task SetManualSuspicionLevelsAsync(ManualSuspicionLevels manualSuspicionLevels) { var executionStrategy = new NpgsqlRetryingExecutionStrategy(db, 3); await executionStrategy.ExecuteAsync(async() => { using (var ts = new TransactionScope(TransactionScopeOption.Required, TimeSpan.FromSeconds(30), TransactionScopeAsyncFlowOption.Enabled)) { db.AddOrUpdate(manualSuspicionLevels, p => p.TaskId == manualSuspicionLevels.TaskId && p.Language == manualSuspicionLevels.Language); await db.SaveChangesAsync().ConfigureAwait(false); ts.Complete(); } }); }
public async Task SaveMostSimilarSubmissionAsync(MostSimilarSubmission mostSimilarSubmission) { await FuncUtils.TrySeveralTimesAsync(async() => { using (var ts = new TransactionScope(TransactionScopeOption.Required, TimeSpan.FromSeconds(30), TransactionScopeAsyncFlowOption.Enabled)) { db.AddOrUpdate(mostSimilarSubmission, p => p.SubmissionId == mostSimilarSubmission.SubmissionId); await db.SaveChangesAsync().ConfigureAwait(false); ts.Complete(); return(0); } }, 3, () => Task.Delay(30)); }
private async Task TrySaveTaskStatisticsParametersAsync(TaskStatisticsParameters parameters, List <TaskStatisticsSourceData> sourceData) { using (var ts = new TransactionScope(TransactionScopeOption.Required, TimeSpan.FromSeconds(30), TransactionScopeAsyncFlowOption.Enabled)) { await db.TaskStatisticsSourceData .Where(d => d.Submission1.TaskId == parameters.TaskId) .DeleteAsync(); db.AddOrUpdate(parameters, p => p.TaskId == parameters.TaskId); db.TaskStatisticsSourceData.AddRange(sourceData); await db.SaveChangesAsync().ConfigureAwait(false); ts.Complete(); } }
/* It's very important that SaveTaskStatisticsParametersAsync() works with disabled EF's Change Tracker */ public async Task SaveTaskStatisticsParametersAsync(TaskStatisticsParameters parameters, List <TaskStatisticsSourceData> sourceData) { var executionStrategy = new NpgsqlRetryingExecutionStrategy(db, 5); await executionStrategy.ExecuteAsync(async() => { using (var ts = new TransactionScope(TransactionScopeOption.Required, TimeSpan.FromSeconds(30), TransactionScopeAsyncFlowOption.Enabled)) { await db.TaskStatisticsSourceData .Where(d => d.Submission1.TaskId == parameters.TaskId && d.Submission1.Language == parameters.Language) .DeleteAsync(); db.AddOrUpdate(parameters, p => p.TaskId == parameters.TaskId && p.Language == parameters.Language); db.TaskStatisticsSourceData.AddRange(sourceData); await db.SaveChangesAsync().ConfigureAwait(false); ts.Complete(); } }); }
public async Task TrySaveMostSimilarSubmissionAsync(MostSimilarSubmission mostSimilarSubmission) { try { var executionStrategy = new NpgsqlRetryingExecutionStrategy(db, 3); await executionStrategy.ExecuteAsync(async() => { using (var ts = new TransactionScope(TransactionScopeOption.Required, TimeSpan.FromSeconds(30), TransactionScopeAsyncFlowOption.Enabled)) { db.AddOrUpdate(mostSimilarSubmission, p => p.SubmissionId == mostSimilarSubmission.SubmissionId); await db.SaveChangesAsync().ConfigureAwait(false); ts.Complete(); return(0); } }); } catch (InvalidOperationException ex) { log.Warn(ex); } }