private async Task <bool> TryOperation(Func <Task> func, string operation = null) { try { await func().ConfigureAwait(false); return(true); } catch (Exception exc) { HttpStatusCode httpStatusCode; string restStatus; if (!AzureStorageUtils.EvaluateException(exc, out httpStatusCode, out restStatus)) { throw; } if (logger.IsEnabled(LogLevel.Trace)) { logger.Trace("{0} failed with httpStatusCode={1}, restStatus={2}", operation, httpStatusCode, restStatus); } if (AzureStorageUtils.IsContentionError(httpStatusCode)) { return(false); } throw; } }
internal async Task <bool> DeleteReminderEntryConditionally(ReminderTableEntry reminderEntry, string eTag) { try { await DeleteTableEntryAsync(reminderEntry, eTag); return(true); }catch (Exception exc) { HttpStatusCode httpStatusCode; string restStatus; if (AzureStorageUtils.EvaluateException(exc, out httpStatusCode, out restStatus)) { if (Logger.IsEnabled(LogLevel.Trace)) { Logger.Trace("DeleteReminderEntryConditionally failed with httpStatusCode={0}, restStatus={1}", httpStatusCode, restStatus); } if (AzureStorageUtils.IsContentionError(httpStatusCode)) { return(false); } } throw; } }
public void AzureTableErrorCode_IsContentionError() { Assert.IsTrue(AzureStorageUtils.IsContentionError(HttpStatusCode.PreconditionFailed)); Assert.IsTrue(AzureStorageUtils.IsContentionError(HttpStatusCode.Conflict)); Assert.IsTrue(AzureStorageUtils.IsContentionError(HttpStatusCode.NotFound)); Assert.IsTrue(AzureStorageUtils.IsContentionError(HttpStatusCode.NotImplemented)); Assert.IsFalse(AzureStorageUtils.IsContentionError((HttpStatusCode)503)); Assert.IsFalse(AzureStorageUtils.IsContentionError((HttpStatusCode)504)); Assert.IsFalse(AzureStorageUtils.IsContentionError((HttpStatusCode)408)); Assert.IsFalse(AzureStorageUtils.IsContentionError((HttpStatusCode)500)); Assert.IsFalse(AzureStorageUtils.IsContentionError((HttpStatusCode)500)); Assert.IsFalse(AzureStorageUtils.IsContentionError((HttpStatusCode)500)); Assert.IsFalse(AzureStorageUtils.IsContentionError((HttpStatusCode)200)); }
internal async Task <string> UpsertRow(ReminderTableEntry reminderEntry) { try { return(await UpsertTableEntryAsync(reminderEntry)); } catch (Exception exc) { HttpStatusCode httpStatusCode; string restStatus; if (AzureStorageUtils.EvaluateException(exc, out httpStatusCode, out restStatus)) { if (Logger.IsEnabled(LogLevel.Trace)) { Logger.Trace("UpsertRow failed with httpStatusCode={0}, restStatus={1}", httpStatusCode, restStatus); } if (AzureStorageUtils.IsContentionError(httpStatusCode)) { return(null); // false; } } throw; } }
private void CheckAlertWriteError(string operation, object data1, string data2, Exception exc) { HttpStatusCode httpStatusCode; string restStatus; if (AzureStorageUtils.EvaluateException(exc, out httpStatusCode, out restStatus) && AzureStorageUtils.IsContentionError(httpStatusCode)) { // log at Verbose, since failure on conditional is not not an error. Will analyze and warn later, if required. if (Logger.IsEnabled(LogLevel.Debug)) { Logger.Debug((int)Utilities.ErrorCode.AzureTable_13, $"Intermediate Azure table write error {operation} to table {TableName} data1 {(data1 ?? "null")} data2 {(data2 ?? "null")}", exc); } } else { Logger.Error((int)Utilities.ErrorCode.AzureTable_14, $"Azure table access write error {operation} to table {TableName} entry {data1}", exc); } }