public static DocumentAlreadyInTransactionException Create(AttemptContext ctx, TransactionGetResult doc) { var msg = $"Document {ctx.Redactor.UserData(doc.Id)} is already in a transaction, atr={doc.TransactionXattrs?.AtrRef?.ToString()}, attemptId = {doc.TransactionXattrs?.Id?.AttemptId ?? "-"}"; return(new DocumentAlreadyInTransactionException(ctx, doc, msg)); }
internal async Task RaiseRetryEventAsync(Exception exception, AttemptContext context, CancellationToken token) { this.RetryHandler?.Invoke(exception, context); if (this.AsyncRetryHandler == null) { return; } await this.AsyncRetryHandler(exception, context, token).ConfigureAwait(context.ExecutionContext.BotPolicyConfiguration.ContinueOnCapturedContext); }
/// <summary> /// Run a query in transaction mode. /// </summary> /// <typeparam name="T">The type of the result. Use <see cref="object"/> for queries with no results.</typeparam> /// <param name="statement">The statement to execute.</param> /// <param name="configure">An action to configure the options for this query.</param> /// <param name="scope">The scope</param> /// <returns>A <see cref="SingleQueryTransactionResult{T}"/> with the query results, if any.</returns> /// <remarks>IMPORTANT: Any KV operations after this query will be run via the query engine, which has performance implications.</remarks> public static async Task <IQueryResult <T> > QueryAsync <T>(this AttemptContext ctx, string statement, Action <TransactionQueryOptions> configure, IScope?scope = null) { var options = new TransactionQueryOptions(); if (configure != null) { configure(options); } return(await ctx.QueryAsync <T>(statement, options, scope).CAF()); }
public override async Task <TResult> ExecuteAsync(IAsyncBotOperation <TResult> operation, ExecutionContext context, CancellationToken token) { var currentAttempt = 1; var tryResult = TryResult <TResult> .Default; while (RetryBotUtils.ShouldExecute(tryResult, base.Configuration, currentAttempt, token)) { tryResult = await this.TryAsync(operation, context, token) .ConfigureAwait(context.BotPolicyConfiguration.ContinueOnCapturedContext); if (tryResult.IsSucceeded) { if (currentAttempt > 1) { await base.Configuration.RaiseRetrySucceededEventAsync(tryResult.OperationResult, AttemptContext.New(currentAttempt, TimeSpan.Zero, context), token) .ConfigureAwait(context.BotPolicyConfiguration.ContinueOnCapturedContext); } return(tryResult.OperationResult); } if (RetryBotUtils.HasMaxAttemptsReached(base.Configuration, currentAttempt)) { break; } var nextDelay = base.Configuration.CalculateNextDelay(currentAttempt, tryResult.Exception, tryResult.OperationResult); await base.Configuration.RaiseRetryEventAsync(tryResult.OperationResult, tryResult.Exception, AttemptContext.New(currentAttempt, nextDelay, context), token) .ConfigureAwait(context.BotPolicyConfiguration.ContinueOnCapturedContext); await RetryBotUtils.WaitAsync(nextDelay, context, token) .ConfigureAwait(context.BotPolicyConfiguration.ContinueOnCapturedContext); currentAttempt++; } token.ThrowIfCancellationRequested(); await base.Configuration.RaiseAsyncRetryLimitReachedEvent(tryResult.Exception, context, token) .ConfigureAwait(context.BotPolicyConfiguration.ContinueOnCapturedContext); throw new MaxRetryAttemptsReachedException(Constants.MaxRetryExceptionMessage, tryResult.Exception, tryResult.OperationResult); }
public override void Execute(IBotOperation operation, ExecutionContext context, CancellationToken token) { var currentAttempt = 1; var tryResult = TryResult.Default; while (RetryBotUtils.ShouldExecute(tryResult, base.Configuration, currentAttempt, token)) { tryResult = this.Try(operation, context, token); if (tryResult.IsSucceeded) { if (currentAttempt > 1) { base.Configuration.RaiseRetrySucceededEvent(AttemptContext.New(currentAttempt, TimeSpan.Zero, context)); } return; } if (RetryBotUtils.HasMaxAttemptsReached(base.Configuration, currentAttempt)) { break; } var nextDelay = base.Configuration.CalculateNextDelay(currentAttempt, tryResult.Exception); base.Configuration.RaiseRetryEvent(tryResult.Exception, AttemptContext.New(currentAttempt, nextDelay, context)); RetryBotUtils.Wait(nextDelay, token); currentAttempt++; } token.ThrowIfCancellationRequested(); base.Configuration.RaiseRetryLimitReachedEvent(tryResult.Exception, context); throw new MaxRetryAttemptsReachedException(Constants.MaxRetryExceptionMessage, tryResult.Exception, null); }
public AttemptExpiredException(AttemptContext ctx, string?msg = null) : base(ctx, msg ?? "Attempt Expired") { }
public ErrorTriage(AttemptContext ctx, ILoggerFactory?loggerFactory) { _ctx = ctx; _logger = loggerFactory?.CreateLogger(nameof(ErrorTriage)); }
public AttemptExpiredException(AttemptContext ctx, string msg, Exception innerException) : base(ctx, msg, innerException) { }
public AttemptException(AttemptContext ctx, string msg, Exception innerException) : base(msg, innerException) { _ctx = ctx; }
internal ActiveTransactionRecordsFullException(AttemptContext ctx, string?msg = null) : base(ctx, msg ?? "Active Transaction Record full") { }
internal void RaiseRetrySucceededEvent(AttemptContext context) => this.RetrySucceededHandler?.Invoke(context);
public AttemptException(AttemptContext ctx, string msg) : base(msg) { _ctx = ctx; }
internal void RaiseRetryEvent(Exception exception, AttemptContext context) => this.RetryHandler?.Invoke(exception, context);
private DocumentAlreadyInTransactionException(AttemptContext ctx, TransactionGetResult doc, string msg) : base(ctx, msg) { Doc = doc; }
public AttemptRepository(AttemptContext context) { _context = context; }
public Task <int?> AfterStagedReplaceComplete(AttemptContext self, string id) => AfterStagedReplaceCompleteImpl(self, id);
public Task <int?> BeforeAtrCommit(AttemptContext self) => BeforeAtrCommitImpl(self);
public Task <int?> BeforeDocCommitted(AttemptContext self, string id) => BeforeDocCommittedImpl(self, id);
public Task <int?> BeforeDocGet(AttemptContext self, string id) => BeforeDocGetImpl(self, id);