Skip to content

Commit

Permalink
Env variable logic for AZ PS upgrade notification (#1015)
Browse files Browse the repository at this point in the history
Set AZUREPS_CHECK_FOR_UPGRADE environment variable to False unless otherwise specified in App Settings, to prevent an expensive check for available version upgrades by AZ PS.
  • Loading branch information
andystaples authored Oct 17, 2023
1 parent 824f5a4 commit 1bf3405
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/Worker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,13 @@ public async static Task Main(string[] args)
}
});

// This must be done before the first Runspace is created, to avoid the creation of a thread by the upgrade checker
SetVersionUpgradeOptOut();

// Create the very first Runspace so the debugger has the target to attach to.
// This PowerShell instance is shared by the first PowerShellManager instance created in the pool,
// and the dependency manager (used to download dependent modules if needed).

var firstPowerShellInstance = Utils.NewPwshInstance();
var pwshVersion = Utils.GetPowerShellVersion(firstPowerShellInstance);
LogPowerShellVersion(pwshVersion);
Expand All @@ -101,6 +105,15 @@ public async static Task Main(string[] args)
await requestProcessor.ProcessRequestLoop();
}

private static void SetVersionUpgradeOptOut()
{
string checkForUpgrade = Environment.GetEnvironmentVariable("AZUREPS_CHECK_FOR_UPGRADE");
if (string.IsNullOrWhiteSpace(checkForUpgrade))
{
Environment.SetEnvironmentVariable("AZUREPS_CHECK_FOR_UPGRADE", "False");
}
}

// Warm up the PowerShell instance so that the subsequent function load and invocation requests are faster
private static void WarmUpPowerShell(System.Management.Automation.PowerShell firstPowerShellInstance)
{
Expand Down

0 comments on commit 1bf3405

Please sign in to comment.