in src/PatchOrchestrationApplication/NodeAgentNTService/src/Manager/TimerManager.cs [200:305]
private void ScheduleTimer()
{
try
{
if (!this.CheckApplicationExists())
{
_eventSource.InfoMessage("Application deleted. Removing NT service...");
this._windowsUpdateManager.ResetStateMachine();
this.RemoveSelf();
return;
}
// If cancellation token is canceled or application is not found
if (this._cancellationToken.IsCancellationRequested)
{
_eventSource.InfoMessage("Canceled timer.");
return;
}
NodeAgentSfUtilityExitCodes exitCode = this._nodeAgentSfUtility.GetWuOperationState(
TimeSpan.FromMinutes(this._serviceSettings.OperationTimeOutInMinutes));
_eventSource.InfoMessage("Current Wu state: {0}", exitCode);
if (exitCode == NodeAgentSfUtilityExitCodes.RestartRequested)
{
_eventSource.ErrorMessage("Not able to restart system.");
//wait for sometime before retrying. This delay is recommended if posting health reports.
if (this._helper.WaitOnTask(Task.Delay(TimeSpan.FromMinutes(WaitTimeInMinutes)),
this._cancellationToken))
{
this.ScheduleWindowsUpdates();
this.ScheduleTimer();
}
return;
}
else if (exitCode == NodeAgentSfUtilityExitCodes.RestartCompleted)
{
this.ScheduleWindowsUpdates();
this.CreateNewCheckpointFile();
this.ScheduleTimer();
return;
}
CheckpointFileData fileData = this.ReadCheckpointFile();
if (fileData.rescheduleNeeded)
{
// If total retries are exhausted, schedule the call back for next interval mentioned in Settings.xml.
if (this.IncrementRetryCount() == false)
{
if (this._windowsUpdateManager.ResetStateMachine())
{
this.UpdateSettingsAndCreateCheckpoint();
this.CreateNewCheckpointFile();
}
else
{
if (this._helper.WaitOnTask(Task.Delay(TimeSpan.FromMinutes(WaitTimeInMinutes)),
this._cancellationToken))
{
this.ScheduleTimer();
}
return;
}
}
}
else
{
// Do not update the lastAttemptedTime.
this.UpdateSettingsAndCreateCheckpoint(false);
}
// read checkpoint file after modifications.
fileData = this.ReadCheckpointFile();
// Execute call back
if (this.ScheduleWindowsUpdatesFlag(fileData))
{
bool retryNeeded = this.ScheduleWindowsUpdates();
if (retryNeeded)
{
fileData.rescheduleNeeded = true;
this.WriteCheckpointFile(fileData);
}
else
{
this.CreateNewCheckpointFile();
}
this.ScheduleTimer();
return;
}
}
catch (Exception e)
{
_eventSource.ErrorMessage("ScheduleTimer ended with exception : {0}", e);
}
TimeSpan operationTimeSpan = TimeSpan.FromMinutes(WaitTimeInMinutes);
if (this._helper.WaitOnTask(Task.Delay(operationTimeSpan), this._cancellationToken))
{
this.ScheduleTimer();
}
}