Skip to content

Commit 1103bab

Browse files
authored
[pack][Hotfix][V2]Remove duplicate worker directories from siteextension (#5723)
1 parent 2d6c40c commit 1103bab

File tree

3 files changed

+40
-1
lines changed

3 files changed

+40
-1
lines changed

build.ps1

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,14 @@ function CreateZips([string] $runtimeSuffix) {
226226
Rename-Item "$privateSiteExtensionPath" "$siteExtensionPath\$extensionVersion"
227227
Copy-Item .\src\WebJobs.Script.WebHost\extension.xml "$siteExtensionPath"
228228
ZipContent $siteExtensionPath "$buildOutput\Functions.$extensionVersion$runtimeSuffix.zip"
229+
}
229230

231+
function deleteDuplicateWorkers() {
232+
Write-Host "Deleting workers directory: $privateSiteExtensionPath\32bit\workers"
233+
Remove-Item -Recurse -Force "$privateSiteExtensionPath\32bit\workers" -ErrorAction SilentlyContinue
234+
Write-Host "Moving workers directory:$privateSiteExtensionPath\64bit\workers to" $privateSiteExtensionPath
235+
236+
Move-Item -Path "$privateSiteExtensionPath\64bit\workers" -Destination "$privateSiteExtensionPath\workers"
230237
}
231238

232239
function cleanExtension([string] $bitness) {
@@ -245,6 +252,7 @@ function cleanExtension([string] $bitness) {
245252
$keepRuntimes = @('win', 'win-x86', 'win10-x86', 'win-x64', 'win10-x64')
246253
Get-ChildItem "$privateSiteExtensionPath\$bitness\workers\powershell\runtimes" -Exclude $keepRuntimes -ErrorAction SilentlyContinue |
247254
Remove-Item -Recurse -Force -ErrorAction SilentlyContinue
255+
deleteDuplicateWorkers
248256
}
249257

250258
dotnet --version

src/WebJobs.Script/Workers/Rpc/Configuration/RpcWorkerConfigFactory.cs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ public RpcWorkerConfigFactory(IConfiguration config, ILogger logger, ISystemRunt
3232
_systemRuntimeInformation = systemRuntimeInfo ?? throw new ArgumentNullException(nameof(systemRuntimeInfo));
3333
_environment = environment ?? throw new ArgumentNullException(nameof(environment));
3434
_metricsLogger = metricsLogger;
35-
WorkersDirPath = Path.Combine(Path.GetDirectoryName(new Uri(typeof(RpcWorkerConfigFactory).Assembly.CodeBase).LocalPath), RpcWorkerConstants.DefaultWorkersDirectoryName);
35+
string assemblyLocalPath = Path.GetDirectoryName(new Uri(typeof(RpcWorkerConfigFactory).Assembly.CodeBase).LocalPath);
36+
WorkersDirPath = GetDefaultWorkersDirectory(Directory.Exists);
3637
var workersDirectorySection = _config.GetSection($"{RpcWorkerConstants.LanguageWorkersSectionName}:{WorkerConstants.WorkersDirectorySectionName}");
3738
if (!string.IsNullOrEmpty(workersDirectorySection.Value))
3839
{
@@ -76,6 +77,18 @@ public IList<RpcWorkerConfig> GetConfigs()
7677
}
7778
}
7879

80+
internal static string GetDefaultWorkersDirectory(Func<string, bool> directoryExists)
81+
{
82+
string assemblyLocalPath = Path.GetDirectoryName(new Uri(typeof(RpcWorkerConfigFactory).Assembly.CodeBase).LocalPath);
83+
string workersDirPath = Path.Combine(assemblyLocalPath, RpcWorkerConstants.DefaultWorkersDirectoryName);
84+
if (!directoryExists(workersDirPath))
85+
{
86+
// Site Extension. Default to parent directory
87+
workersDirPath = Path.Combine(Directory.GetParent(assemblyLocalPath).FullName, RpcWorkerConstants.DefaultWorkersDirectoryName);
88+
}
89+
return workersDirPath;
90+
}
91+
7992
internal void BuildWorkerProviderDictionary()
8093
{
8194
AddProviders();

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,24 @@ public void DefaultLanguageWorkersDir()
3939
Assert.Equal(expectedWorkersDir, configFactory.WorkersDirPath);
4040
}
4141

42+
[Fact]
43+
public void GetDefaultWorkersDirectory_Returns_Expected()
44+
{
45+
string assemblyLocalPath = Path.GetDirectoryName(new Uri(typeof(RpcWorkerConfigFactory).Assembly.CodeBase).LocalPath);
46+
string defaultWorkersDirPath = Path.Combine(assemblyLocalPath, RpcWorkerConstants.DefaultWorkersDirectoryName);
47+
Func<string, bool> testDirectoryExists = path =>
48+
{
49+
return false;
50+
};
51+
var expectedWorkersDirIsCurrentDir = Path.Combine(assemblyLocalPath, RpcWorkerConstants.DefaultWorkersDirectoryName);
52+
var expectedWorkersDirIsParentDir = Path.Combine(Directory.GetParent(assemblyLocalPath).FullName, RpcWorkerConstants.DefaultWorkersDirectoryName);
53+
var config = new ConfigurationBuilder().Build();
54+
var testLogger = new TestLogger("test");
55+
56+
Assert.Equal(expectedWorkersDirIsCurrentDir, RpcWorkerConfigFactory.GetDefaultWorkersDirectory(Directory.Exists));
57+
Assert.Equal(expectedWorkersDirIsParentDir, RpcWorkerConfigFactory.GetDefaultWorkersDirectory(testDirectoryExists));
58+
}
59+
4260
[Fact]
4361
public void LanguageWorker_WorkersDir_Set()
4462
{

0 commit comments

Comments
 (0)