private void InstallModule(DependencyInfo module, string installingPath, PowerShell pwsh, ILogger logger)
        {
            logger.Log(isUserOnlyLog: false, LogLevel.Trace, string.Format(PowerShellWorkerStrings.StartedInstallingModule, module.Name, module.ExactVersion));

            int tries = 1;

            while (true)
            {
                try
                {
                    _moduleProvider.SaveModule(pwsh, module.Name, module.ExactVersion, installingPath);

                    var message = string.Format(PowerShellWorkerStrings.ModuleHasBeenInstalled, module.Name, module.ExactVersion);
                    logger.Log(isUserOnlyLog: false, LogLevel.Trace, message);

                    break;
                }
                catch (Exception e)
                {
                    string currentAttempt = GetCurrentAttemptMessage(tries);
                    var    errorMsg       = string.Format(PowerShellWorkerStrings.FailToInstallModule, module.Name, module.ExactVersion, currentAttempt, e.Message);
                    logger.Log(isUserOnlyLog: false, LogLevel.Error, errorMsg);

                    if (tries >= MaxNumberOfTries)
                    {
                        errorMsg = string.Format(PowerShellWorkerStrings.FailToInstallFuncAppDependencies, e.Message);
                        throw new DependencyInstallationException(errorMsg, e);
                    }
                }

                // Wait for 2^(tries-1) seconds between retries. In this case, it would be 1, 2, and 4 seconds, respectively.
                var waitTimeSpan = TimeSpan.FromSeconds(Math.Pow(2, tries - 1));
                Thread.Sleep(waitTimeSpan);

                tries++;
            }
        }
        public void InstallSnapshot(
            IEnumerable <DependencyManifestEntry> dependencies,
            string targetPath,
            PowerShell pwsh,
            ILogger logger)
        {
            logger.Log(isUserOnlyLog: false, LogLevel.Trace, PowerShellWorkerStrings.InstallingFunctionAppDependentModules);

            var installingPath = CreateInstallingSnapshot(targetPath);

            try
            {
                foreach (DependencyInfo module in GetExactVersionsOfDependencies(dependencies))
                {
                    logger.Log(isUserOnlyLog: false, LogLevel.Trace, string.Format(PowerShellWorkerStrings.StartedInstallingModule, module.Name, module.ExactVersion));

                    int tries = 1;

                    while (true)
                    {
                        try
                        {
                            _moduleProvider.SaveModule(pwsh, module.Name, module.ExactVersion, installingPath);

                            var message = string.Format(PowerShellWorkerStrings.ModuleHasBeenInstalled, module.Name, module.ExactVersion);
                            logger.Log(isUserOnlyLog: false, LogLevel.Trace, message);

                            break;
                        }
                        catch (Exception e)
                        {
                            string currentAttempt = GetCurrentAttemptMessage(tries);
                            var    errorMsg       = string.Format(PowerShellWorkerStrings.FailToInstallModule, module.Name, module.ExactVersion, currentAttempt, e.Message);
                            logger.Log(isUserOnlyLog: false, LogLevel.Error, errorMsg);

                            if (tries >= MaxNumberOfTries)
                            {
                                errorMsg = string.Format(PowerShellWorkerStrings.FailToInstallFuncAppDependencies, e.Message);
                                throw new DependencyInstallationException(errorMsg, e);
                            }
                        }

                        // Wait for 2^(tries-1) seconds between retries. In this case, it would be 1, 2, and 4 seconds, respectively.
                        var waitTimeSpan = TimeSpan.FromSeconds(Math.Pow(2, tries - 1));
                        Thread.Sleep(waitTimeSpan);

                        tries++;
                    }
                }

                _storage.PromoteInstallingSnapshotToInstalledAtomically(targetPath);
            }
            catch (Exception e)
            {
                var message = string.Format(PowerShellWorkerStrings.FailedToInstallDependenciesSnapshot, targetPath);
                logger.Log(isUserOnlyLog: false, LogLevel.Warning, message, e);
                _storage.RemoveSnapshot(installingPath);
                throw;
            }
            finally
            {
                _moduleProvider.Cleanup(pwsh);
            }
        }