Skip to content

Commit

Permalink
Merge pull request #160 from purva-vasudeo/puvasude/updatedeploystatu…
Browse files Browse the repository at this point in the history
…s-first-req

Moving first request to Kudu in update deployment status api
  • Loading branch information
purva-vasudeo committed Dec 1, 2020
2 parents a207ad9 + 807dfdf commit 1904bd3
Showing 1 changed file with 31 additions and 4 deletions.
35 changes: 31 additions & 4 deletions Kudu.Core/Deployment/FetchDeploymentManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,26 @@ public async Task PerformDeployment(DeploymentInfoBase deploymentInfo,
// The branch or commit id to deploy
string deployBranch = !String.IsNullOrEmpty(deploymentInfo.CommitId) ? deploymentInfo.CommitId : targetBranch;

try
{
_tracer.Trace($"Before sending {Constants.BuildRequestReceived} status to /api/updatedeploystatus");
if (PostDeploymentHelper.IsAzureEnvironment())
{
// Parse the changesetId into a GUID
// The FE hook allows only GUID as a deployment id
// If the id is already in GUID format nothing will happen
// If it doesn't have the necessary format for a GUID, and exception will be thrown
var changeSet = repository.GetChangeSet(deployBranch);
updateStatusObj = new DeployStatusApiResult(Constants.BuildRequestReceived, Guid.Parse(changeSet.Id).ToString());
await SendDeployStatusUpdate(updateStatusObj);
}
}
catch (Exception e)
{
_tracer.TraceError($"Exception while sending {Constants.BuildRequestReceived} status to /api/updatedeploystatus. " +
$"Entry in the operations table for the deployment status may not have been created. {e}");
}

// In case the commit or perhaps fetch do no-op.
if (deploymentInfo.TargetChangeset != null && ShouldDeploy(repository, deploymentInfo, deployBranch))
{
Expand All @@ -225,9 +245,9 @@ public async Task PerformDeployment(DeploymentInfoBase deploymentInfo,
// Here, we don't need to update the working files, since we know Fetch left them in the correct state
// unless for GenericHandler where specific commitId is specified
bool deploySpecificCommitId = !String.IsNullOrEmpty(deploymentInfo.CommitId);
if (PostDeploymentHelper.IsAzureEnvironment() && deploymentInfo.ExternalDeploymentId != null)
if (updateStatusObj != null)
{
updateStatusObj = new DeployStatusApiResult(Constants.BuildInProgress, deploymentInfo.ExternalDeploymentId);
updateStatusObj.DeploymentStatus = Constants.BuildInProgress;
await SendDeployStatusUpdate(updateStatusObj);
}

Expand Down Expand Up @@ -304,7 +324,7 @@ await PostDeploymentHelper.PerformAutoSwap(
/// </summary>
/// <param name="updateStatusObj">Obj containing status to save to DB</param>
/// <returns></returns>
private async Task SendDeployStatusUpdate(DeployStatusApiResult updateStatusObj)
private async Task<bool> SendDeployStatusUpdate(DeployStatusApiResult updateStatusObj)
{
int attemptCount = 0;
try
Expand All @@ -313,17 +333,24 @@ await OperationManager.AttemptAsync(async () =>
{
attemptCount++;
_tracer.Trace($" PostAsync - Trying to send {updateStatusObj.DeploymentStatus} deployment status to {Constants.UpdateDeployStatusPath}");
_tracer.Trace($" PostAsync - Trying to send {updateStatusObj.DeploymentStatus} deployment status to {Constants.UpdateDeployStatusPath}. " +
$"DeploymentId is {updateStatusObj.DeploymentId}");
await PostDeploymentHelper.PostAsync(Constants.UpdateDeployStatusPath, _environment.RequestId, JsonConvert.SerializeObject(updateStatusObj));
}, 3, 5*1000);

// If no exception is thrown, the operation was a success
return true;
}
catch (Exception ex)
{
_tracer.TraceError($"Failed to request a post deployment status. Number of attempts: {attemptCount}. Exception: {ex}");
// Do not throw the exception
// We fail silently so that we do not fail the build altogether if this call fails
//throw;

return false;
}
}

Expand Down

0 comments on commit 1904bd3

Please sign in to comment.