Skip to content
This repository has been archived by the owner on Jul 30, 2024. It is now read-only.
/ NuGet.Jobs Public archive

[Revalidation] Request revalidation #477

Merged
merged 7 commits into from
Jul 9, 2018
Merged

Conversation

loic-sharma
Copy link
Contributor

Adds the core logic of the revalidation job so that it wakes up, determines the next package to revalidate, and enqueues it to the Orchestrator. This change does not cover:

Addresses https://github.com/NuGet/Engineering/issues/1443

/// Check whether the killswitch has been activated. If it has, all revalidation operations should be halted.
/// </summary>
/// <returns>Whether the killswitch has been activated.</returns>
Task<bool> IsKillswitchActiveAsync();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't it be CancellationToken that you'd pass around (a property in this exact interface?) instead of a function returning bool that has to be called every once in a while? We'd get cancellation of library functions essentially for free then...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The killswitch value comes from an Azure blob that will be polled, hence this API design.

I need to update this PR, but, the killswitch will be implemented using this: NuGet/ServerCommon#169


namespace NuGet.Services.Revalidate
{
public interface ITelemetryService
public interface ISingletonService
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Documentation?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added

/// Delay the current task to achieve the desired revalidation rate.
/// </summary>
/// <returns>Delay the task to ensure the desired revalidation rate.</returns>
Task OnRevalidationEnqueuedAsync();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Method that produces a task that delays should probably have Delay in the name :)
Same for the method below.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like that. Fixed


var next = await _validationContext.PackageRevalidations
.Where(r => r.Enqueued == null)
.Where(r => r.Completed == false)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

!r.Completed?..

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please don't hate me but I like how those two Wheres look next to each other. Rules are mean to be broken! 🙈

.Where(p => p.NormalizedVersion == revalidation.PackageNormalizedVersion)
.FirstOrDefaultAsync();

return (package == null || package.PackageStatusKey == PackageStatus.Deleted);
Copy link
Contributor

@agr agr Jul 6, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code retrieves complete Package object from DB, checks its single property, then discards it. Consider adding something like .Select((PackageStatus?)r.PackageStatus) (not sure what's exact type here) before calling FirstOrDefault.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch. Fixed

return;
}
}
while (runTime.Elapsed <= _config.ShutdownWaitInterval);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some crazy idea: instead of creating a stopwatch to track the execution time, we could start a var t = Task.Delay(_config.ShutdownWaitInterval), then just check t.IsCompleted as the while condition. Never tried myself.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mm, I think I prefer the Stopwatch pattern. Stopwatches are known to be very accurate, whereas I'm not sure how accurate Task.Delay + IsCompleted would be.

namespace NuGet.Services.Revalidate
{
public interface IHealthService
{
Copy link
Contributor

@cristinamanum cristinamanum Jul 9, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this interface meant to be used by all of our jobs?

Copy link
Contributor Author

@loic-sharma loic-sharma Jul 9, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This interface is specific to the revalidate job only. It will only check the health of services that may be affected by revalidations (so it won't check the gallery or the statistics pipeline)

{
using (_telemetryService.TrackDurationToStartNextRevalidation())
{
// Check whether a revalidation can be started.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe add comments for the conditions when a revalidation cannot be started.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added. Let me know if you think the comment can be improved.

@loic-sharma loic-sharma changed the base branch from master to dev July 9, 2018 23:03
@loic-sharma loic-sharma merged commit 6b53394 into dev Jul 9, 2018
@loic-sharma loic-sharma deleted the loshar-send-revalidation branch July 9, 2018 23:04
joelverhagen pushed a commit that referenced this pull request Oct 26, 2020
Adds the core logic of the revalidation job so that it wakes up, determines the next package to revalidate, and enqueues it to the Orchestrator.

Addresses https://github.com/NuGet/Engineering/issues/1443
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants