Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Set the command timeout to 5 seconds when recording package statistics #1856

Merged
merged 3 commits into from

2 participants

@jeffhandley

Illustrative pull request - not expected to be accepted. This is how I was thinking we'd set the command timeout to 5 seconds for recording package statistics.

Fixes #1865

@anurse
Collaborator

Well, I don't really see a big reason why we can't just take this as-is :). Looks good to me.

@anurse anurse Merge branch 'master' into jeffhand/commandtimeout
Conflicts:
	src/NuGetGallery/Controllers/ApiController.cs
0428afe
@anurse anurse merged commit c2ff710 into from
@anurse anurse deleted the branch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jan 28, 2014
  1. @jeffhandley
Commits on Jan 29, 2014
  1. @jeffhandley
Commits on Jan 30, 2014
  1. @anurse

    Merge branch 'master' into jeffhand/commandtimeout

    anurse authored
    Conflicts:
    	src/NuGetGallery/Controllers/ApiController.cs
This page is out of date. Refresh to see the latest.
View
6 src/NuGetGallery.Core/Entities/EntitiesContext.cs
@@ -59,6 +59,11 @@ public override int SaveChanges()
Set<T>().Remove(entity);
}
+ public void SetCommandTimeout(int? seconds)
+ {
+ ((IObjectContextAdapter)this).ObjectContext.CommandTimeout = seconds;
+ }
+
#pragma warning disable 618 // TODO: remove Package.Authors completely once prodution services definitely no longer need it
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
@@ -207,5 +212,6 @@ protected override void OnModelCreating(DbModelBuilder modelBuilder)
.HasRequired(cp => cp.PackageRegistration);
}
#pragma warning restore 618
+
}
}
View
1  src/NuGetGallery.Core/Entities/IEntitiesContext.cs
@@ -13,5 +13,6 @@ public interface IEntitiesContext
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1716:IdentifiersShouldNotMatchKeywords", MessageId = "Set", Justification="This is to match the EF terminology.")]
IDbSet<T> Set<T>() where T : class;
void DeleteOnCommit<T>(T entity) where T : class;
+ void SetCommandTimeout(int? seconds);
}
}
View
8 src/NuGetGallery/Controllers/ApiController.cs
@@ -110,7 +110,6 @@ public partial class ApiController : AppController
{
var stats = new PackageStatistics
{
- // IMPORTANT: Timestamp is managed by the database.
IPAddress = Request.UserHostAddress,
UserAgent = Request.UserAgent,
Package = package,
@@ -118,8 +117,11 @@ public partial class ApiController : AppController
DependentPackage = Request.Headers["NuGet-DependentPackage"],
ProjectGuids = Request.Headers["NuGet-ProjectGuids"],
};
- //Temporarily disable stats.
- // PackageService.AddDownloadStatistics(stats);
+
+ // Only allow this to take up to 5 seconds. Any longer and we just lose the data; oh well.
+ EntitiesContext.SetCommandTimeout(5);
+
+ PackageService.AddDownloadStatistics(stats);
}
catch (ReadOnlyModeException)
{
View
6 tests/NuGetGallery.Facts/TestUtils/FakeEntitiesContext.cs
@@ -108,6 +108,12 @@ public void VerifyCommitChanges()
{
Assert.True(areChangesSaved, "SaveChanges() has not been called on the entity context.");
}
+
+
+ public void SetCommandTimeout(int? seconds)
+ {
+ throw new NotSupportedException();
+ }
}
}
Something went wrong with that request. Please try again.