Skip to content

Commit e452fe6

Browse files
authored
Support codeless non-dotnet functions (#6878)
1 parent e36e9f6 commit e452fe6

File tree

3 files changed

+56
-2
lines changed

3 files changed

+56
-2
lines changed

src/WebJobs.Script/Host/ScriptHost.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ public async Task InitializeAsync(CancellationToken cancellationToken = default)
282282
{
283283
string runtimeStack = _workerRuntime;
284284

285-
if (!string.IsNullOrEmpty(_environment.GetEnvironmentVariable(RpcWorkerConstants.FunctionWorkerRuntimeSettingName)))
285+
if (!string.IsNullOrEmpty(runtimeStack))
286286
{
287287
// Appending the runtime version is currently only enabled for linux consumption. This will be eventually enabled for
288288
// Windows Consumption as well.
@@ -304,7 +304,8 @@ public async Task InitializeAsync(CancellationToken cancellationToken = default)
304304

305305
// Initialize worker function invocation dispatcher only for valid functions after creating function descriptors
306306
// Dispatcher not needed for non-proxy codeless function.
307-
var filteredFunctionMetadata = functionMetadataList.Where(m => m.IsProxy() || !m.IsCodeless());
307+
// Disptacher needed for non-dotnet codeless functions
308+
var filteredFunctionMetadata = functionMetadataList.Where(m => m.IsProxy() || !Utility.IsCodelessDotNetLanguageFunction(m));
308309
await _functionDispatcher.InitializeAsync(Utility.GetValidFunctions(filteredFunctionMetadata, Functions), cancellationToken);
309310

310311
GenerateFunctions(directTypes);

src/WebJobs.Script/Utility.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -634,6 +634,20 @@ public static bool IsSupportedRuntime(string workerRuntime, IEnumerable<RpcWorke
634634
return workerConfigs.Any(config => string.Equals(config.Description.Language, workerRuntime, StringComparison.OrdinalIgnoreCase));
635635
}
636636

637+
public static bool IsCodelessDotNetLanguageFunction(FunctionMetadata functionMetadata)
638+
{
639+
if (functionMetadata == null)
640+
{
641+
throw new ArgumentNullException(nameof(functionMetadata));
642+
}
643+
644+
if (functionMetadata.IsCodeless() && !string.IsNullOrEmpty(functionMetadata.Language))
645+
{
646+
return IsDotNetLanguageFunction(functionMetadata.Language);
647+
}
648+
return false;
649+
}
650+
637651
private static bool ContainsFunctionWithWorkerRuntime(IEnumerable<FunctionMetadata> functions, string workerRuntime)
638652
{
639653
if (string.Equals(workerRuntime, RpcWorkerConstants.DotNetLanguageWorkerName, StringComparison.OrdinalIgnoreCase))

test/WebJobs.Script.Tests/UtilityTests.cs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -676,6 +676,45 @@ public async Task Test_LogAutorestGeneratedJson_With_AutorestGeneratedJson(strin
676676
}
677677
}
678678

679+
[Theory]
680+
[InlineData(true)]
681+
[InlineData(false)]
682+
public void IsCodelessDotNetLanguageFunction_Returns_Expected(bool setIsCodeless)
683+
{
684+
FunctionMetadata func1 = new FunctionMetadata()
685+
{
686+
Name = "func1",
687+
Language = DotNetScriptTypes.CSharp
688+
};
689+
690+
FunctionMetadata func2 = new FunctionMetadata()
691+
{
692+
Name = "func2",
693+
Language = DotNetScriptTypes.DotNetAssembly
694+
};
695+
696+
FunctionMetadata nodeFunc = new FunctionMetadata()
697+
{
698+
Name = "func3",
699+
Language = "node"
700+
};
701+
702+
if (setIsCodeless)
703+
{
704+
func1.Properties.Add("IsCodeless", true);
705+
func2.Properties.Add("IsCodeless", true);
706+
nodeFunc.Properties.Add("IsCodeless", true);
707+
Assert.True(Utility.IsCodelessDotNetLanguageFunction(func1));
708+
Assert.True(Utility.IsCodelessDotNetLanguageFunction(func2));
709+
}
710+
else
711+
{
712+
Assert.False(Utility.IsCodelessDotNetLanguageFunction(func1));
713+
Assert.False(Utility.IsCodelessDotNetLanguageFunction(func2));
714+
Assert.False(Utility.IsCodelessDotNetLanguageFunction(nodeFunc));
715+
}
716+
}
717+
679718
private static void VerifyLogLevel(IList<LogMessage> allLogs, string msg, LogLevel expectedLevel)
680719
{
681720
var message = allLogs.Where(l => l.FormattedMessage.Contains(msg)).FirstOrDefault();

0 commit comments

Comments
 (0)