internal string Initialize(ILogger logger) { try { // Parse and process the function app dependencies defined in the manifest. _dependenciesFromManifest = _storage.GetDependencies().ToArray(); if (!_dependenciesFromManifest.Any()) { logger.Log(isUserOnlyLog: true, LogLevel.Warning, PowerShellWorkerStrings.FunctionAppDoesNotHaveDependentModulesToInstall); return(null); } _currentSnapshotPath = _installedDependenciesLocator.GetPathWithAcceptableDependencyVersionsInstalled() ?? _storage.CreateNewSnapshotPath(); _purger.SetCurrentlyUsedSnapshot(_currentSnapshotPath, logger); return(_currentSnapshotPath); } catch (Exception e) { var errorMsg = string.Format(PowerShellWorkerStrings.FailToInstallFuncAppDependencies, e.Message); throw new DependencyInstallationException(errorMsg, e); } }
/// <summary> /// Returns the path for the new dependencies snapshot. /// </summary> public string InstallAndPurgeSnapshots(Func <PowerShell> pwshFactory, ILogger logger) { try { // Purge before installing a new snapshot, as we may be able to free some space. _purger.Purge(logger); if (IsAnyInstallationStartedRecently()) { return(null); } var nextSnapshotPath = _storage.CreateNewSnapshotPath(); using (var pwsh = pwshFactory()) { _installer.InstallSnapshot( _dependencyManifest, nextSnapshotPath, pwsh, // Background dependency upgrades are optional because the current // worker already has a good enough snapshot, and nothing depends on // the new snapshot yet, so installation failures will not affect // function invocations. DependencySnapshotInstallationMode.Optional, logger); } // Now that a new snapshot has been installed, there is a chance an old snapshot can be purged. _purger.Purge(logger); return(nextSnapshotPath); } catch (Exception e) { logger.Log( isUserOnlyLog: false, RpcLog.Types.Level.Warning, string.Format(PowerShellWorkerStrings.DependenciesUpgradeSkippedMessage, e.Message)); return(null); } }