pulumi/sdk/dotnet/Pulumi/Deployment/Deployment_Inline.cs
Josh Studt ef9a1e4e40
[sdk/dotnet] - Thread-safe concurrency-friendly global state (#6139)
* changes necessary for concurrent thread safe global deployment state

* update changelog

* backtrack resource package changes, enable test parallelization

* cleanup comment

* add copyright to new file

* resolve paralellization differences after merging automation api preview

* no longer need to null deployment instance

* Update CHANGELOG.md

* whoops - switch to CHANGELOG_PENDING

* Update CHANGELOG_PENDING.md

move note down to improvements

* attempt to exclude dynami assemblies

Co-authored-by: Anton Tayanovskyy <anton.tayanovskyy@gmail.com>
2021-04-09 15:55:34 -04:00

58 lines
2 KiB
C#

// Copyright 2016-2021, Pulumi Corporation
using System;
using System.Runtime.ExceptionServices;
using System.Threading.Tasks;
namespace Pulumi
{
public partial class Deployment
{
private Deployment(InlineDeploymentSettings settings)
{
if (settings is null)
throw new ArgumentNullException(nameof(settings));
_projectName = settings.Project;
_stackName = settings.Stack;
_isDryRun = settings.IsDryRun;
SetAllConfig(settings.Config);
if (string.IsNullOrEmpty(settings.MonitorAddr)
|| string.IsNullOrEmpty(settings.EngineAddr)
|| string.IsNullOrEmpty(_projectName)
|| string.IsNullOrEmpty(_stackName))
{
throw new InvalidOperationException("Inline execution was not provided the necessary parameters to run the Pulumi engine.");
}
Serilog.Log.Debug("Creating Deployment Engine.");
Engine = new GrpcEngine(settings.EngineAddr);
Serilog.Log.Debug("Created Deployment Engine.");
Serilog.Log.Debug("Creating Deployment Monitor.");
Monitor = new GrpcMonitor(settings.MonitorAddr);
Serilog.Log.Debug("Created Deployment Monitor.");
_runner = new Runner(this);
_logger = new Logger(this, Engine);
}
internal static async Task<ExceptionDispatchInfo?> RunInlineAsync(InlineDeploymentSettings settings, Func<IRunner, Task<ExceptionDispatchInfo?>> func)
{
ExceptionDispatchInfo? exceptionDispatchInfo = null;
await CreateRunnerAndRunAsync(
() => new Deployment(settings),
async runner =>
{
exceptionDispatchInfo = await func(runner).ConfigureAwait(false);
return 1;
})
.ConfigureAwait(false);
return exceptionDispatchInfo;
}
}
}