Skip to content

Commit

Permalink
Remove unused executionContext
Browse files Browse the repository at this point in the history
  • Loading branch information
jpalac committed Sep 6, 2023
1 parent cb1ee00 commit 7ff5e43
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 50 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ public InProcessFunctionEndpoint(
IServiceProvider serviceProvider)
{
this.serverlessInterceptor = serverlessInterceptor;
endpointFactory = _ => externallyManagedContainerEndpoint.Start(serviceProvider);
endpointFactory = () => externallyManagedContainerEndpoint.Start(serviceProvider);
}

public async Task Send(object message, SendOptions options, ExecutionContext executionContext, ILogger functionsLogger = null, CancellationToken cancellationToken = default)
{
FunctionsLoggerFactory.Instance.SetCurrentLogger(functionsLogger);

await InitializeEndpointIfNecessary(executionContext, functionsLogger, cancellationToken).ConfigureAwait(false);
await InitializeEndpointIfNecessary(cancellationToken).ConfigureAwait(false);
await endpoint.Send(message, options, cancellationToken).ConfigureAwait(false);
}

Expand All @@ -42,7 +42,7 @@ public async Task Send<T>(Action<T> messageConstructor, SendOptions options, Exe
{
FunctionsLoggerFactory.Instance.SetCurrentLogger(functionsLogger);

await InitializeEndpointIfNecessary(executionContext, functionsLogger, cancellationToken).ConfigureAwait(false);
await InitializeEndpointIfNecessary(cancellationToken).ConfigureAwait(false);
await endpoint.Send(messageConstructor, options, cancellationToken).ConfigureAwait(false);
}

Expand All @@ -55,7 +55,7 @@ public async Task Publish(object message, PublishOptions options, ExecutionConte
{
FunctionsLoggerFactory.Instance.SetCurrentLogger(functionsLogger);

await InitializeEndpointIfNecessary(executionContext, functionsLogger, cancellationToken).ConfigureAwait(false);
await InitializeEndpointIfNecessary(cancellationToken).ConfigureAwait(false);
await endpoint.Publish(message, options, cancellationToken).ConfigureAwait(false);
}

Expand All @@ -68,7 +68,7 @@ public async Task Publish<T>(Action<T> messageConstructor, PublishOptions option
{
FunctionsLoggerFactory.Instance.SetCurrentLogger(functionsLogger);

await InitializeEndpointIfNecessary(executionContext, functionsLogger, cancellationToken).ConfigureAwait(false);
await InitializeEndpointIfNecessary(cancellationToken).ConfigureAwait(false);
await endpoint.Publish(messageConstructor, options, cancellationToken).ConfigureAwait(false);
}

Expand All @@ -81,7 +81,7 @@ public async Task Subscribe(Type eventType, SubscribeOptions options, ExecutionC
{
FunctionsLoggerFactory.Instance.SetCurrentLogger(functionsLogger);

await InitializeEndpointIfNecessary(executionContext, functionsLogger, cancellationToken).ConfigureAwait(false);
await InitializeEndpointIfNecessary(cancellationToken).ConfigureAwait(false);
await endpoint.Subscribe(eventType, options, cancellationToken).ConfigureAwait(false);
}

Expand All @@ -94,7 +94,7 @@ public async Task Unsubscribe(Type eventType, UnsubscribeOptions options, Execut
{
FunctionsLoggerFactory.Instance.SetCurrentLogger(functionsLogger);

await InitializeEndpointIfNecessary(executionContext, functionsLogger, cancellationToken).ConfigureAwait(false);
await InitializeEndpointIfNecessary(cancellationToken).ConfigureAwait(false);
await endpoint.Unsubscribe(eventType, options, cancellationToken).ConfigureAwait(false);
}

Expand All @@ -111,7 +111,7 @@ public async Task ProcessNonAtomic(
{
FunctionsLoggerFactory.Instance.SetCurrentLogger(functionsLogger);

await InitializeEndpointIfNecessary(executionContext, functionsLogger, cancellationToken)
await InitializeEndpointIfNecessary(cancellationToken)
.ConfigureAwait(false);

try
Expand Down Expand Up @@ -147,7 +147,7 @@ public async Task ProcessAtomic(

try
{
await InitializeEndpointIfNecessary(executionContext, functionsLogger, cancellationToken).ConfigureAwait(false);
await InitializeEndpointIfNecessary(cancellationToken).ConfigureAwait(false);
}
catch (Exception)
{
Expand Down Expand Up @@ -251,7 +251,7 @@ static AzureServiceBusTransportTransaction CreateTransaction(string messageParti
"Azure.Security.KeyVault.Secrets.dll"
};

internal async Task InitializeEndpointIfNecessary(ExecutionContext executionContext, ILogger logger, CancellationToken cancellationToken)
internal async Task InitializeEndpointIfNecessary(CancellationToken cancellationToken)
{
if (pipeline == null)
{
Expand All @@ -260,8 +260,7 @@ internal async Task InitializeEndpointIfNecessary(ExecutionContext executionCont
{
if (pipeline == null)
{
var functionExecutionContext = new FunctionExecutionContext(executionContext, logger);
endpoint = await endpointFactory(functionExecutionContext).ConfigureAwait(false);
endpoint = await endpointFactory().ConfigureAwait(false);

pipeline = serverlessInterceptor.PipelineInvoker;
}
Expand All @@ -276,7 +275,7 @@ internal async Task InitializeEndpointIfNecessary(ExecutionContext executionCont
PipelineInvoker pipeline;
IEndpointInstance endpoint;

readonly Func<FunctionExecutionContext, Task<IEndpointInstance>> endpointFactory;
readonly Func<Task<IEndpointInstance>> endpointFactory;
readonly SemaphoreSlim semaphoreLock = new SemaphoreSlim(initialCount: 1, maxCount: 1);
readonly ServerlessInterceptor serverlessInterceptor;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,6 @@
[assembly: System.Runtime.CompilerServices.InternalsVisibleTo(@"ServiceBus.Tests, PublicKey=00240000048000009400000006020000002400005253413100040000010001007f16e21368ff041183fab592d9e8ed37e7be355e93323147a1d29983d6e591b04282e4da0c9e18bd901e112c0033925eb7d7872c2f1706655891c5c9d57297994f707d16ee9a8f40d978f064ee1ffc73c0db3f4712691b23bf596f75130f4ec978cf78757ec034625a5f27e6bb50c618931ea49f6f628fd74271c32959efb1c5")]
namespace NServiceBus
{
public class FunctionExecutionContext
{
public FunctionExecutionContext(Microsoft.Azure.WebJobs.ExecutionContext executionContext, Microsoft.Extensions.Logging.ILogger logger) { }
public Microsoft.Azure.WebJobs.ExecutionContext ExecutionContext { get; }
public Microsoft.Extensions.Logging.ILogger Logger { get; }
}
public static class FunctionsHostBuilderExtensions
{
public static void UseNServiceBus(this Microsoft.Azure.Functions.Extensions.DependencyInjection.IFunctionsHostBuilder functionsHostBuilder, System.Action<NServiceBus.ServiceBusTriggeredEndpointConfiguration> configurationFactory = null) { }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public async Task Should_load_handlers_from_assembly_when_using_FunctionsHostBui
var endpoint = new InProcessFunctionEndpoint(startableEndpoint, serverless, serviceProvider);

// we need to process an actual message to have the endpoint being created
await endpoint.InitializeEndpointIfNecessary(new Microsoft.Azure.WebJobs.ExecutionContext(), null, CancellationToken.None);
await endpoint.InitializeEndpointIfNecessary(CancellationToken.None);

// The message handler assembly should be loaded now because scanning should find and load the handler assembly
Assert.True(AppDomain.CurrentDomain.GetAssemblies().Any(a => a.FullName == "Testing.Handlers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"));
Expand Down

0 comments on commit 7ff5e43

Please sign in to comment.