Skip to content

Commit 3090d8d

Browse files
authored
[RpcWorker]Add environment variable FUNCTIONS_WORKER_DIRECTORY (#6201)
1 parent a7e941a commit 3090d8d

File tree

4 files changed

+11
-4
lines changed

4 files changed

+11
-4
lines changed

src/WebJobs.Script/Workers/Rpc/RpcWorkerProcess.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,13 @@ internal class RpcWorkerProcess : WorkerProcess
1919
private readonly Uri _serverUri;
2020
private readonly string _scriptRootPath;
2121
private readonly WorkerProcessArguments _workerProcessArguments;
22+
private readonly string _workerDirectory;
2223

2324
internal RpcWorkerProcess(string runtime,
2425
string workerId,
2526
string rootScriptPath,
2627
Uri serverUri,
27-
WorkerProcessArguments workerProcessArguments,
28+
RpcWorkerConfig rpcWorkerConfig,
2829
IScriptEventManager eventManager,
2930
IWorkerProcessFactory processFactory,
3031
IProcessRegistry processRegistry,
@@ -40,12 +41,14 @@ internal RpcWorkerProcess(string runtime,
4041
_workerId = workerId;
4142
_serverUri = serverUri;
4243
_scriptRootPath = rootScriptPath;
43-
_workerProcessArguments = workerProcessArguments;
44+
_workerProcessArguments = rpcWorkerConfig.Arguments;
45+
_workerDirectory = rpcWorkerConfig.Description.WorkerDirectory;
4446
}
4547

4648
internal override Process CreateWorkerProcess()
4749
{
4850
var workerContext = new RpcWorkerContext(Guid.NewGuid().ToString(), RpcWorkerConstants.DefaultMaxMessageLengthBytes, _workerId, _workerProcessArguments, _scriptRootPath, _serverUri);
51+
workerContext.EnvironmentVariables.Add(WorkerConstants.FunctionsWorkerDirectorySettingName, _workerDirectory);
4952
return _processFactory.CreateWorkerProcess(workerContext);
5053
}
5154

src/WebJobs.Script/Workers/Rpc/RpcWorkerProcessFactory.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public RpcWorkerProcessFactory(IRpcServer rpcServer,
3838
public IWorkerProcess Create(string workerId, string runtime, string scriptRootPath, RpcWorkerConfig workerConfig)
3939
{
4040
ILogger workerProcessLogger = _loggerFactory.CreateLogger($"Worker.rpcWorkerProcess.{runtime}.{workerId}");
41-
return new RpcWorkerProcess(runtime, workerId, scriptRootPath, _rpcServer.Uri, workerConfig.Arguments, _eventManager, _workerProcessFactory, _processRegistry, workerProcessLogger, _consoleLogSource, _metricsLogger);
41+
return new RpcWorkerProcess(runtime, workerId, scriptRootPath, _rpcServer.Uri, workerConfig, _eventManager, _workerProcessFactory, _processRegistry, workerProcessLogger, _consoleLogSource, _metricsLogger);
4242
}
4343
}
4444
}

src/WebJobs.Script/Workers/WorkerConstants.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ public static class WorkerConstants
2020
public const string WorkersDirectorySectionName = "workersDirectory";
2121
public const string WorkerDirectorySectionName = "workerDirectory";
2222

23+
// Environment variables names
24+
public const string FunctionsWorkerDirectorySettingName = "FUNCTIONS_WORKER_DIRECTORY";
25+
2326
// Worker description constants
2427
public const string WorkerDescriptionDefaultExecutablePath = "defaultExecutablePath";
2528
public const string WorkerDescriptionDefaultWorkerPath = "defaultWorkerPath";

test/WebJobs.Script.Tests/Workers/Rpc/RpcWorkerProcessTests.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,12 @@ public RpcWorkerProcessTests()
2424
var rpcServer = new TestRpcServer();
2525
var languageWorkerConsoleLogSource = new Mock<IWorkerConsoleLogSource>();
2626
var testEnv = new TestEnvironment();
27+
var testWorkerConfigs = TestHelpers.GetTestWorkerConfigs();
2728
_rpcWorkerProcess = new RpcWorkerProcess("node",
2829
"testworkerId",
2930
"testrootPath",
3031
rpcServer.Uri,
31-
null,
32+
testWorkerConfigs.ElementAt(0),
3233
_eventManager.Object,
3334
workerProcessFactory.Object,
3435
processRegistry.Object,

0 commit comments

Comments
 (0)