Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@ public abstract class WorkerDescription
/// </summary>
public string DefaultExecutablePath { get; set; }

/// <summary>
/// Gets or sets the working directory for worker executable. Defaults to the Function App root directory.
/// If set, it will be used as the working directory for the worker executable.
/// If not set, the Function App root directory will be used as the working directory for the worker executable.
/// </summary>
public string ExecutableWorkingDirectory { get; set; }

/// <summary>
/// Gets or sets the default path to the worker.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ public RpcWorkerDescription ApplyProfile(RpcWorkerDescription defaultWorkerDescr
updatedDescription.Language = UseProfileOrDefault(ProfileDescription.Language, defaultWorkerDescription.Language);
updatedDescription.WorkerDirectory = UseProfileOrDefault(ProfileDescription.WorkerDirectory, defaultWorkerDescription.WorkerDirectory);
updatedDescription.IsDisabled = ProfileDescription.IsDisabled ?? defaultWorkerDescription.IsDisabled ?? false;
updatedDescription.ExecutableWorkingDirectory = UseProfileOrDefault(ProfileDescription.ExecutableWorkingDirectory, defaultWorkerDescription.ExecutableWorkingDirectory);
return updatedDescription;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ internal void AddProvider(string workerDir)
if (ShouldAddWorkerConfig(workerDescription.Language))
{
workerDescription.FormatWorkerPathIfNeeded(_systemRuntimeInformation, _environment, _logger);
workerDescription.FormatWorkingDirectoryIfNeeded();
workerDescription.FormatArgumentsIfNeeded(_logger);
workerDescription.ThrowIfFileNotExists(workerDescription.DefaultWorkerPath, nameof(workerDescription.DefaultWorkerPath));
workerDescription.ExpandEnvironmentVariables();
Expand Down
5 changes: 5 additions & 0 deletions src/WebJobs.Script/Workers/Rpc/RpcWorkerDescription.cs
Original file line number Diff line number Diff line change
Expand Up @@ -262,5 +262,10 @@ private string GetSanitizedRuntimeVersion(string version)

return match.Value;
}

internal void FormatWorkingDirectoryIfNeeded()
{
ExecutableWorkingDirectory = ExecutableWorkingDirectory?.Replace(RpcWorkerConstants.WorkerDirectoryPath, WorkerDirectory);
}
}
}
4 changes: 3 additions & 1 deletion src/WebJobs.Script/Workers/Rpc/RpcWorkerProcess.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ internal class RpcWorkerProcess : WorkerProcess
private readonly string _workerId;
private readonly Uri _serverUri;
private readonly string _scriptRootPath;
private readonly string _workerExecutableWorkingDirectory;
private readonly WorkerProcessArguments _workerProcessArguments;
private readonly string _workerDirectory;
private readonly IOptions<FunctionsHostingConfigOptions> _hostingConfigOptions;
Expand Down Expand Up @@ -49,6 +50,7 @@ internal RpcWorkerProcess(string runtime,
_workerId = workerId;
_serverUri = serverUri;
_scriptRootPath = rootScriptPath;
_workerExecutableWorkingDirectory = rpcWorkerConfig.Description.ExecutableWorkingDirectory ?? _scriptRootPath;
_workerProcessArguments = rpcWorkerConfig.Arguments;
_workerDirectory = rpcWorkerConfig.Description.WorkerDirectory;
_hostingConfigOptions = hostingConfigOptions;
Expand All @@ -57,7 +59,7 @@ internal RpcWorkerProcess(string runtime,

internal override Process CreateWorkerProcess()
{
var workerContext = new RpcWorkerContext(Guid.NewGuid().ToString(), RpcWorkerConstants.DefaultMaxMessageLengthBytes, _workerId, _workerProcessArguments, _scriptRootPath, _serverUri);
var workerContext = new RpcWorkerContext(Guid.NewGuid().ToString(), RpcWorkerConstants.DefaultMaxMessageLengthBytes, _workerId, _workerProcessArguments, _workerExecutableWorkingDirectory, _serverUri);
workerContext.EnvironmentVariables.Add(WorkerConstants.FunctionsWorkerDirectorySettingName, _workerDirectory);
workerContext.EnvironmentVariables.Add(WorkerConstants.FunctionsApplicationDirectorySettingName, _scriptRootPath);
workerContext.EnvironmentVariables.Add(RpcWorkerConstants.FunctionWorkerRuntimeVersionSettingName, _environment.GetEnvironmentVariable(RpcWorkerConstants.FunctionWorkerRuntimeVersionSettingName));
Expand Down
20 changes: 20 additions & 0 deletions test/WebJobs.Script.Tests.Shared/TestHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,26 @@ public static IList<RpcWorkerConfig> GetTestWorkerConfigsNoLanguage()
};
}

public static IList<RpcWorkerConfig> GetTestWorkerConfigsWithExecutableWorkingDirectory()
{
return new List<RpcWorkerConfig>()
{
new RpcWorkerConfig
{
Description = new RpcWorkerDescription
{
Extensions = new List<string>()
{
{ ".jar" }
},
Language = "java",
WorkerDirectory = "testDir",
ExecutableWorkingDirectory = "executableDirectory"
}
},
};
}

public static string CreateOfflineFile()
{
// create a test offline file
Expand Down
Loading