in Source/NuGetGallery.Operations/Tasks/ReplicatePackageStatisticsTask.cs [187:240]
private int Replicate(string source, string destination, int batchSize, int expectedSourceMaxQueryTime, int pauseDuration)
{
Log.Trace("Check for data to replicate.");
int total = 0;
bool hasWork;
do
{
int originalKey = GetLastOriginalKey(destination);
DateTime before = DateTime.Now;
DownloadBatch batch = GetDownloadRecords(source, originalKey, batchSize);
DateTime after = DateTime.Now;
TimeSpan duration = after - before;
Log.Trace(string.Format("source query duration: {0} seconds", duration.TotalSeconds));
if (batch.Rows.Count > 0)
{
hasWork = true;
PutDownloadRecords(destination, batch, CancellationToken);
if (CancellationToken.IsCancellationRequested)
{
return total;
}
Log.Trace(string.Format("replicated {0} records", batch.Rows.Count));
total += batch.Rows.Count;
if (duration.TotalSeconds > expectedSourceMaxQueryTime)
{
Log.Trace("previous source query exceeded threshold so pausing");
Thread.Sleep(pauseDuration * 1000);
}
}
else
{
hasWork = false;
}
if (CancellationToken.IsCancellationRequested)
{
return total;
}
}
while (hasWork);
return total;
}