Ejemplo n.º 1
0
        internal async Task <ExecutionResult> ExecuteAsync(T input, CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();

            _logger.RequestingLock();
            await LockStrategy.RequestLockAsync(cancellationToken);

            _logger.Executing();

            using var context = new ChainContext(Name, _serviceProvider, cancellationToken);

            try
            {
                context.EventBroker.Publish(new ChainExecutionStartedEvent(context));

                var startTickCount = Environment.TickCount64;
                var result         = await ExecuteRootConnector(input, context);

                var duration = TimeSpan.FromMilliseconds(Environment.TickCount64 - startTickCount);

                LogResult(result);

                if (result is { Status : ExecutionResultStatus.Faulted, Exception : {} })
                {
                    await context.EventBroker.PublishAsync(new ChainExceptionEvent(context, result.Exception));
                }

                context.EventBroker.Publish(new ChainExecutionResultEvent(context, duration, result));

                LockStrategy.ReleaseLock();

                return(result);
            }
Ejemplo n.º 2
0
        internal async Task <ExecutionResult> ExecuteAsync(T input, CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();

            _logger.RequestingLock();
            await LockStrategy.RequestLockAsync(cancellationToken);

            _logger.Executing();

            using var context = new ChainContext(Name, _serviceProvider, cancellationToken);
            try
            {
                context.EventBroker.Publish(new ChainExecutionStartedEvent(context));

                var startTickCount = Environment.TickCount64;
                await _root.ProcessAsync(input, context);

                var duration = TimeSpan.FromMilliseconds(Environment.TickCount64 - startTickCount);

                if (context.Result == ExecutionResult.Unknown)
                {
                    context.SetResult(ExecutionResult.Completed);
                }
                else if (context.Exception is { } exception)
                {
                    await context.EventBroker.PublishAsync(new ChainExceptionEvent(context, exception));
                }

                context.EventBroker.Publish(new ChainExecutionResultEvent(context, duration, context.Result,
                                                                          context.ResultReason, context.Exception));

                LockStrategy.ReleaseLock();
            }
            catch (Exception e)
            {
                try
                {
                    _logger.LogCritical(e, "Critical failure");
                }
                finally
                {
                    Environment.Exit(2013);
                }
            }

            return(context.Result);
        }
Ejemplo n.º 3
0
 /// <summary>
 ///     Sets the deployment lock strategy, the default is <seealso cref="LockStrategyDefault" />
 /// </summary>
 /// <param name="deploymentLockStrategy">lock strategy</param>
 /// <returns>itself</returns>
 public DeploymentOptions WithDeploymentLockStrategy(LockStrategy deploymentLockStrategy)
 {
     DeploymentLockStrategy = deploymentLockStrategy;
     return this;
 }