Merge pull request #1307 from tgstation/1304-YetAnotherDbIssue

Wirewraith, what the hell?
This commit is contained in:
Jordan Brown
2021-08-28 15:23:38 -04:00
committed by GitHub
3 changed files with 28 additions and 22 deletions
@@ -289,6 +289,7 @@ namespace Tgstation.Server.Host.Components.Deployment
};
logger.LogInformation(Repository.Repository.OriginTrackingErrorTemplate, repoSha);
databaseContext.RevisionInformations.Add(revInfo);
databaseContext.Instances.Attach(revInfo.Instance);
await databaseContext.Save(cancellationToken).ConfigureAwait(false);
}
@@ -308,27 +308,14 @@ namespace Tgstation.Server.Host.Components
cancellationToken)
.ConfigureAwait(false);
RevisionInformation currentRevInfo = null;
Task<RevisionInformation> LoadRevInfo() => databaseContext.RevisionInformations
.AsQueryable()
.Where(x => x.CommitSha == startSha && x.Instance.Id == metadata.Id)
.Include(x => x.ActiveTestMerges).ThenInclude(x => x.TestMerge)
.FirstOrDefaultAsync(cancellationToken);
.AsQueryable()
.Where(x => x.CommitSha == startSha && x.Instance.Id == metadata.Id)
.Include(x => x.ActiveTestMerges).ThenInclude(x => x.TestMerge)
.FirstOrDefaultAsync(cancellationToken);
RevisionInformation currentRevInfo = null;
var hasDbChanges = false;
// take appropriate auto update actions
var shouldSyncTracked = false;
var currentRevInfoTask = LoadRevInfo();
var result = await repo.MergeOrigin(
repositorySettings.CommitterName,
repositorySettings.CommitterEmail,
NextProgressReporter(),
cancellationToken)
.ConfigureAwait(false);
async Task UpdateRevInfo(string currentHead, bool onOrigin, IEnumerable<RevInfoTestMerge> updatedTestMerges)
{
if (currentRevInfo == null)
@@ -363,14 +350,25 @@ namespace Tgstation.Server.Host.Components
hasDbChanges = true;
}
// build current commit data if it's missing
await UpdateRevInfo(repo.Head, false, null).ConfigureAwait(false);
var result = await repo.MergeOrigin(
repositorySettings.CommitterName,
repositorySettings.CommitterEmail,
NextProgressReporter(),
cancellationToken)
.ConfigureAwait(false);
var preserveTestMerges = repositorySettings.AutoUpdatesKeepTestMerges.Value;
var remoteDeploymentManager = remoteDeploymentManagerFactory.CreateRemoteDeploymentManager(
metadata,
repo.RemoteGitProvider.Value);
// take appropriate auto update actions
var shouldSyncTracked = false;
if (result.HasValue)
{
currentRevInfo = await currentRevInfoTask.ConfigureAwait(false);
var updatedTestMerges = await remoteDeploymentManager.RemoveMergedTestMerges(
repo,
repositorySettings,
@@ -139,6 +139,9 @@ namespace Tgstation.Server.Host.Components.Repository
{
if (exception.Message == "too many redirects or authentication replays")
throw new JobException("Bad git credentials exchange!", exception);
if (exception.Message == ErrorCode.RepoCredentialsRequired.Describe())
throw new JobException(ErrorCode.RepoCredentialsRequired);
}
/// <summary>
@@ -963,8 +966,12 @@ namespace Tgstation.Server.Host.Components.Repository
// workaround for https://github.com/libgit2/libgit2/issues/3820
// kill off the modules/ folder in .git and try again
CheckBadCredentialsException(ex);
logger.LogWarning(ex, "Initial update of submodule {0} failed. Deleting .git submodule directory and re-attempting...", submodule.Name);
await ioMananger.DeleteDirectory($".git/modules/{submodule.Path}", cancellationToken).ConfigureAwait(false);
logger.LogWarning(ex, "Initial update of submodule {0} failed. Deleting submodule directories and re-attempting...", submodule.Name);
await Task.WhenAll(
ioMananger.DeleteDirectory($".git/modules/{submodule.Path}", cancellationToken),
ioMananger.DeleteDirectory(submodule.Path, cancellationToken))
.ConfigureAwait(false);
logger.LogTrace("Second update attempt for submodule {0}...", submodule.Name);
try