Exemplo n.º 1
0
            public ParallelAsyncOperation(IEnumerable <IShard> shards, IAsyncShardOperation operation, CancellationToken cancellationToken)
            {
                this.operation = operation;

                var timeoutCts = new CancellationTokenSource(OperationTimeoutInSeconds);
                var linkedCts  = cancellationToken.CanBeCanceled
                                        ? CancellationTokenSource.CreateLinkedTokenSource(cancellationToken, timeoutCts.Token)
                                        : CancellationTokenSource.CreateLinkedTokenSource(timeoutCts.Token);

                this.task = ExecuteForShardsAsync(shards, linkedCts.Token).ContinueWith(t =>
                {
                    if (t.IsCanceled)
                    {
                        if (timeoutCts.IsCancellationRequested)
                        {
                            throw CreateAndLogTimeoutException(operation.OperationName);
                        }
                        linkedCts.Token.ThrowIfCancellationRequested();
                    }
                    if (t.Exception != null)
                    {
                        throw WrapAndLogShardException(operation.OperationName, t.Exception.GetBaseException());
                    }
                });
            }
 public async Task ApplyAsync(IEnumerable <IShard> shards, IAsyncShardOperation operation, CancellationToken cancellationToken)
 {
     foreach (var shard in GetNextOrderingOfShards(shards))
     {
         var shardOperation = operation.PrepareAsync(shard);
         await shardOperation(cancellationToken);
     }
 }
        public async Task <T> ApplyAsync <T>(IEnumerable <IShard> shards, IAsyncShardOperation <T> operation, IExitStrategy <T> exitStrategy, CancellationToken cancellationToken)
        {
            foreach (var shard in GetNextOrderingOfShards(shards))
            {
                var shardOperation = operation.PrepareAsync(shard);
                var result         = await shardOperation(cancellationToken);

                if (result != null && exitStrategy.AddResult(result, shard))
                {
                    Log.Debug("Short-circuiting operation {0} after execution against shard {1}", operation.OperationName, shard);
                    break;
                }
            }
            return(exitStrategy.CompileResults());
        }
Exemplo n.º 4
0
 /// <inheritdoc />
 public Task <T> ApplyAsync <T>(IEnumerable <IShard> shards, IAsyncShardOperation <T> operation, IExitStrategy <T> exitStrategy, CancellationToken cancellationToken)
 {
     return(new ParallelAsyncOperation <T>(shards, operation, exitStrategy, cancellationToken).CompleteAsync());
 }
Exemplo n.º 5
0
 /// <inheritdoc />
 public Task ApplyAsync(IEnumerable <IShard> shards, IAsyncShardOperation operation, CancellationToken cancellationToken)
 {
     return(new ParallelAsyncOperation(shards, operation, cancellationToken).CompleteAsync());
 }
Exemplo n.º 6
0
 public Task <T> ExecuteAsync <T>(IAsyncShardOperation <T> operation, IExitStrategy <T> exitStrategy, CancellationToken cancellationToken)
 {
     throw new NotSupportedException();
 }
Exemplo n.º 7
0
 public Task ExecuteAsync(IAsyncShardOperation operation, CancellationToken cancellationToken)
 {
     throw new NotSupportedException();
 }