Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion WebJobs.Script.sln
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.0.31717.71
VisualStudioVersion = 17.14.36623.8 d17.14
MinimumVisualStudioVersion = 15.0.0.0
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{16351B76-87CA-4A8C-80A1-3DD83A0C4AA6}"
EndProject
Expand Down
4 changes: 2 additions & 2 deletions src/WebJobs.Script.Grpc/Channel/GrpcWorkerChannelFactory.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.

using System;
Expand All @@ -17,7 +17,7 @@

namespace Microsoft.Azure.WebJobs.Script.Grpc
{
public class GrpcWorkerChannelFactory : IRpcWorkerChannelFactory
internal class GrpcWorkerChannelFactory : IRpcWorkerChannelFactory
{
private readonly ILoggerFactory _loggerFactory = null;
private readonly IRpcWorkerProcessFactory _rpcWorkerProcessFactory = null;
Expand Down
4 changes: 2 additions & 2 deletions src/WebJobs.Script.Grpc/Eventing/GrpcEvent.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.

using Microsoft.Azure.WebJobs.Script.Eventing;
using Microsoft.Azure.WebJobs.Script.Grpc.Messages;

namespace Microsoft.Azure.WebJobs.Script.Grpc.Eventing
{
public class GrpcEvent : ScriptEvent
internal class GrpcEvent : ScriptEvent
{
internal GrpcEvent(string workerId, StreamingMessage message, MessageOrigin origin = MessageOrigin.Host)
: base(message.ContentCase.ToString(), EventSources.Rpc)
Expand Down
4 changes: 2 additions & 2 deletions src/WebJobs.Script.Grpc/Eventing/InboundGrpcEvent.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.

using Microsoft.Azure.WebJobs.Script.Grpc.Messages;

namespace Microsoft.Azure.WebJobs.Script.Grpc.Eventing
{
public class InboundGrpcEvent : GrpcEvent
internal class InboundGrpcEvent : GrpcEvent
{
public InboundGrpcEvent(string workerId, StreamingMessage message) : base(workerId, message, MessageOrigin.Worker)
{
Expand Down
4 changes: 2 additions & 2 deletions src/WebJobs.Script.Grpc/Eventing/OutboundGrpcEvent.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.

using Microsoft.Azure.WebJobs.Script.Grpc.Messages;

namespace Microsoft.Azure.WebJobs.Script.Grpc.Eventing
{
public class OutboundGrpcEvent : GrpcEvent
internal class OutboundGrpcEvent : GrpcEvent
{
public OutboundGrpcEvent(string workerId, StreamingMessage message) : base(workerId, message, MessageOrigin.Host)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.

using System;
Expand All @@ -15,7 +15,7 @@

namespace Microsoft.Azure.WebJobs.Script.Workers
{
internal class FunctionInvocationDispatcherFactory : IFunctionInvocationDispatcherFactory
internal class FunctionInvocationDispatcherFactory : IFunctionInvocationDispatcherFactory, IDisposable
{
private readonly IFunctionInvocationDispatcher _functionDispatcher;

Expand Down Expand Up @@ -65,5 +65,11 @@ public FunctionInvocationDispatcherFactory(IOptions<ScriptJobHostOptions> script
}

public IFunctionInvocationDispatcher GetFunctionDispatcher() => _functionDispatcher;

public void Dispose()
{
// This is a "provider" rather than a "factory". We are responsible for disposing.
_functionDispatcher.Dispose();
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.

using System.Threading;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.

namespace Microsoft.Azure.WebJobs.Script.Workers
{
public enum FunctionInvocationDispatcherState
internal enum FunctionInvocationDispatcherState
{
/// <summary>
/// The FunctionDispatcher has not yet been created
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.

using System;
using Microsoft.Azure.WebJobs.Script.Workers.Http;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Options;

namespace Microsoft.Azure.WebJobs.Script.Rpc.Hosting
{
internal sealed class HttpScriptHostRecycleOptionsSetup : IPostConfigureOptions<ScriptHostRecycleOptions>
{
private readonly IOptions<HttpWorkerOptions> _httpWorkerOptions;
private readonly IConfiguration _configuration;

public HttpScriptHostRecycleOptionsSetup(
IOptions<HttpWorkerOptions> httpWorkerOptions, IConfiguration configuration)
{
_httpWorkerOptions = httpWorkerOptions ?? throw new ArgumentNullException(nameof(httpWorkerOptions));
_configuration = configuration ?? throw new ArgumentNullException(nameof(configuration));
}

public void PostConfigure(string name, ScriptHostRecycleOptions options)
{
// Enforcing sequential host restarts when a user-specified custom handler port is configured to prevent multiple processes from attempting to bind to the same port concurrently.
if (_httpWorkerOptions.Value.IsPortManuallySet)
{
options.SequentialHostRestartRequired = true;
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.

using System;
using System.Runtime.InteropServices;
using Microsoft.Azure.WebJobs.Host.Scale;
using Microsoft.Azure.WebJobs.Script;
using Microsoft.Azure.WebJobs.Script.Config;
using Microsoft.Azure.WebJobs.Script.Description;
using Microsoft.Azure.WebJobs.Script.Host;
using Microsoft.Azure.WebJobs.Script.Rpc;
using Microsoft.Azure.WebJobs.Script.Rpc.Configuration;
using Microsoft.Azure.WebJobs.Script.Rpc.Hosting;
using Microsoft.Azure.WebJobs.Script.Scale;
using Microsoft.Azure.WebJobs.Script.WebHost;
using Microsoft.Azure.WebJobs.Script.Workers;
using Microsoft.Azure.WebJobs.Script.Workers.Http;
using Microsoft.Azure.WebJobs.Script.Workers.Rpc;
using Microsoft.Extensions.DependencyInjection.Extensions;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Options;

namespace Microsoft.Extensions.DependencyInjection;

public static class RpcServiceCollectionExtensions
{
public static IServiceCollection AddRpcScriptHostServices(this IServiceCollection services)
{
ArgumentNullException.ThrowIfNull(services);

// HTTP Worker
services.AddSingleton<IHttpWorkerProcessFactory, HttpWorkerProcessFactory>();
services.AddSingleton<IHttpWorkerChannelFactory, HttpWorkerChannelFactory>();
services.AddSingleton<IHttpWorkerService, DefaultHttpWorkerService>();
services.TryAddEnumerable(ServiceDescriptor.Singleton<IFunctionProvider, HttpWorkerFunctionProvider>());

//Worker Function Invocation dispatcher
services.AddSingleton<IFunctionInvocationDispatcherFactory, FunctionInvocationDispatcherFactory>();

// Rpc Worker
services.AddSingleton<IJobHostRpcWorkerChannelManager, JobHostRpcWorkerChannelManager>();
services.AddSingleton<IRpcFunctionInvocationDispatcherLoadBalancer, RpcFunctionInvocationDispatcherLoadBalancer>();

services.AddSingleton<IHostedService, WorkerConcurrencyManager>();

// Configuration
services.AddSingleton<IPostConfigureOptions<ScriptHostRecycleOptions>, HttpScriptHostRecycleOptionsSetup>();
services.ConfigureOptions<HttpWorkerOptionsSetup>();
services.ConfigureOptions<RpcFunctionMetadataOptionsSetup>();
services.ConfigureOptions<RpcScriptHostRecycleOptionsSetup>();

services.TryAddEnumerable(ServiceDescriptor.Singleton<IHostedService, FunctionInvocationDispatcherShutdownManager>());

services.AddSingleton<IWorkerFunctionDescriptorProviderFactory, RpcWorkerFunctionDescriptorProviderFactory>();
services.AddSingleton<IScriptHostLifecycleService, RpcScriptHostLifecycleService>();
services.AddSingleton<IScriptHostWorkerManager, RpcScriptHostWorkerManager>();

return services;
}

public static IServiceCollection AddCommonRpcServices(this IServiceCollection services)
{
ArgumentNullException.ThrowIfNull(services);

// Add Language Worker Service
services.AddSingleton<IRpcWorkerProcessFactory, RpcWorkerProcessFactory>();

services.AddSingleton<IWorkerProcessFactory, DefaultWorkerProcessFactory>();
services.TryAddSingleton<IWebHostRpcWorkerChannelManager, WebHostRpcWorkerChannelManager>();
services.TryAddSingleton<IWorkerFunctionMetadataProvider, WorkerFunctionMetadataProvider>();
services.AddSingleton<IScriptHostWorkerManager, RpcScriptHostWorkerManager>();
services.TryAddEnumerable(ServiceDescriptor.Singleton<IConcurrencyThrottleProvider, WorkerChannelThrottleProvider>());
services.AddSingleton<IWebHostWorkerManager, RpcWebHostWorkerManager>();

services.AddManagedHostedService<RpcInitializationService>();

AddProcessRegistry(services);

return services;
}

private static void AddProcessRegistry(IServiceCollection services)
{
// W3WP already manages job objects
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)
&& !ScriptSettingsManager.Instance.IsAppServiceEnvironment)
{
services.AddSingleton<IProcessRegistry, JobObjectRegistry>();
}
else
{
services.AddSingleton<IProcessRegistry, EmptyProcessRegistry>();
}
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.

namespace Microsoft.Azure.WebJobs.Script.Workers.Http
{
public enum CustomHandlerType
internal enum CustomHandlerType
{
Http = 0,
None = 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

namespace Microsoft.Azure.WebJobs.Script.Workers.Http
{
public class HttpWorkerOptions : IOptionsFormatter
internal class HttpWorkerOptions : IOptionsFormatter
{
private int? _port;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.

using Microsoft.Azure.WebJobs.Script.Workers.Http;
using Microsoft.Extensions.Options;

namespace Microsoft.Azure.WebJobs.Script.Rpc.Configuration;

internal class RpcFunctionMetadataOptionsSetup : IConfigureOptions<FunctionMetadataOptions>
{
private readonly bool _isHttpWorker;

public RpcFunctionMetadataOptionsSetup(IOptions<HttpWorkerOptions> httpOptions)
{
_isHttpWorker = httpOptions.Value.Description is not null;
}

public void Configure(FunctionMetadataOptions options)
{
// certain validations do not apply to HTTP workers
options.SkipScriptFileValidation = _isHttpWorker;
options.SkipRuntimeValidation = _isHttpWorker;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.

using Microsoft.Azure.WebJobs.Script.Workers.Http;
using Microsoft.Extensions.Options;

namespace Microsoft.Azure.WebJobs.Script.Rpc.Configuration;

internal class RpcScriptHostRecycleOptionsSetup : IConfigureOptions<ScriptHostRecycleOptions>
{
private readonly IOptions<HttpWorkerOptions> _httpOptions;

public RpcScriptHostRecycleOptionsSetup(IOptions<HttpWorkerOptions> httpOptions)
{
_httpOptions = httpOptions;
}

public void Configure(ScriptHostRecycleOptions options)
{
if (_httpOptions.Value.IsPortManuallySet)
{
options.SequentialHostRestartRequired = true;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.

using System.Collections;
using System.Collections.Generic;
using Microsoft.Azure.WebJobs.Extensions.Http;

namespace Microsoft.Azure.WebJobs.Script.Workers.Http
{
public sealed class CustomHandlerHttpOptions
internal sealed class CustomHandlerHttpOptions
{
/// <summary>
/// Gets or sets the default authorization level for custom handler HTTP worker routes.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

namespace Microsoft.Azure.WebJobs.Script.Workers.Http
{
public class DefaultHttpWorkerService : IHttpWorkerService
internal class DefaultHttpWorkerService : IHttpWorkerService
{
private readonly HttpClient _httpClient;
private readonly HttpWorkerOptions _httpWorkerOptions;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.

using System.Collections.Generic;

namespace Microsoft.Azure.WebJobs.Script.Workers.Http
{
public class HttpScriptInvocationContext
internal class HttpScriptInvocationContext
{
public IDictionary<string, object> Data { get; set; } = new Dictionary<string, object>();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.

using System;
Expand All @@ -8,7 +8,7 @@

namespace Microsoft.Azure.WebJobs.Script.Workers
{
public static class HttpScriptInvocationContextExtensions
internal static class HttpScriptInvocationContextExtensions
{
public static HttpRequestMessage ToHttpRequestMessage(this HttpScriptInvocationContext context, string requestUri)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.

using System.Collections.Generic;

namespace Microsoft.Azure.WebJobs.Script.Workers.Http
{
public class HttpScriptInvocationResult
internal class HttpScriptInvocationResult
{
public object ReturnValue { get; set; }

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.

using System;
Expand All @@ -10,7 +10,7 @@

namespace Microsoft.Azure.WebJobs.Script.Workers.Http
{
public static class HttpScriptInvocationResultExtensions
internal static class HttpScriptInvocationResultExtensions
{
public static ScriptInvocationResult ToScriptInvocationResult(this HttpScriptInvocationResult httpScriptInvocationResult, ScriptInvocationContext scriptInvocationContext)
{
Expand Down
Loading
Loading