Merge pull request #127 from NzbDrone/wtf-gtfo

New: automatically switch back to master if current branch is invalid
This commit is contained in:
Keivan Beigi 2014-10-29 11:25:42 -07:00
commit 1eaef4360d
4 changed files with 27 additions and 2 deletions

View File

@ -23,6 +23,13 @@ namespace NzbDrone.Core.Test.UpdateTests
Subject.GetLatestUpdate("master", new Version(2, 0)).Should().NotBeNull();
}
[Test]
public void should_get_master_if_branch_doesnt_exit()
{
UseRealHttp();
Subject.GetLatestUpdate("invalid_branch", new Version(2, 0)).Should().NotBeNull();
}
[Test]
public void should_get_recent_updates()
@ -37,6 +44,7 @@ namespace NzbDrone.Core.Test.UpdateTests
recent.Should().OnlyContain(c => c.ReleaseDate.Year == 2014);
recent.Should().OnlyContain(c => c.Changes.New != null);
recent.Should().OnlyContain(c => c.Changes.Fixed != null);
recent.Should().OnlyContain(c => c.Branch == branch);
}
}
}

View File

@ -57,7 +57,7 @@ namespace NzbDrone.Core.Jobs
{
new ScheduledTask{ Interval = 1, TypeName = typeof(TrackedCommandCleanupCommand).FullName},
new ScheduledTask{ Interval = 1, TypeName = typeof(CheckForFinishedDownloadCommand).FullName},
new ScheduledTask{ Interval = 1*60, TypeName = typeof(ApplicationUpdateCommand).FullName},
new ScheduledTask{ Interval = 6*60, TypeName = typeof(ApplicationUpdateCommand).FullName},
new ScheduledTask{ Interval = 1*60, TypeName = typeof(TrimLogCommand).FullName},
new ScheduledTask{ Interval = 3*60, TypeName = typeof(UpdateSceneMappingCommand).FullName},
new ScheduledTask{ Interval = 6*60, TypeName = typeof(CheckHealthCommand).FullName},

View File

@ -1,4 +1,5 @@
using NLog;
using System;
using NLog;
using NzbDrone.Common.EnvironmentInfo;
using NzbDrone.Common.Instrumentation.Extensions;
using NzbDrone.Core.Configuration;
@ -40,6 +41,21 @@ namespace NzbDrone.Core.Update
{
_logger.ProgressDebug("No update available.");
}
else if (latestAvailable.Branch != _configFileProvider.Branch)
{
try
{
_logger.Warn("[{0}] isn't a valid branch. Switching back to [master]", _configFileProvider.Branch);
var config = _configFileProvider.GetConfigDictionary();
config["Branch"] = _configFileProvider.Branch;
_configFileProvider.SaveConfigDictionary(config);
}
catch (Exception e)
{
_logger.ErrorException("Couldn't revert back to master.", e);
}
}
return latestAvailable;
}

View File

@ -11,5 +11,6 @@ namespace NzbDrone.Core.Update
public String Url { get; set; }
public UpdateChanges Changes { get; set; }
public String Hash { get; set; }
public String Branch { get; set; }
}
}