Skip to content

Commit

Permalink
Wrap ServerBootstrapper with automatic retry
Browse files Browse the repository at this point in the history
Fixes #291
  • Loading branch information
odinserj committed Jan 27, 2015
1 parent 8a6604f commit 193c698
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
9 changes: 7 additions & 2 deletions src/Hangfire.Core/BackgroundJobServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ internal virtual IServerSupervisor GetBootstrapSupervisor()
_storage,
new Lazy<IServerSupervisor>(GetSupervisors));

return new ServerSupervisor(
return CreateSupervisor(
bootstrapper,
new ServerSupervisorOptions
{
Expand Down Expand Up @@ -162,7 +162,12 @@ private IEnumerable<IServerComponent> GetCommonComponents()

private static ServerSupervisor CreateSupervisor(IServerComponent component)
{
return new ServerSupervisor(new AutomaticRetryServerComponentWrapper(component));
return CreateSupervisor(component, new ServerSupervisorOptions());
}

private static ServerSupervisor CreateSupervisor(IServerComponent component, ServerSupervisorOptions options)
{
return new ServerSupervisor(new AutomaticRetryServerComponentWrapper(component), options);
}
}
}
2 changes: 1 addition & 1 deletion src/Hangfire.Core/Server/ServerBootstrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public void Execute(CancellationToken cancellationToken)

public override string ToString()
{
return "Server Core";
return "Server Bootstrapper";
}

public void Dispose()
Expand Down
11 changes: 9 additions & 2 deletions tests/Hangfire.Core.Tests/BackgroundJobServerFacts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,14 +92,21 @@ public void Dispose_DisposesBootstrapSupervisor()
}

[Fact]
public void GetBootstrapSupervisor_ReturnsNonNullResult()
public void GetBootstrapSupervisor_ReturnsBootstrapper_WrappedWithAutomaticRetry()
{
// Arrange
var server = CreateServer();

// Act
var supervisor = server.GetBootstrapSupervisor();

// Assert
Assert.NotNull(supervisor);
Assert.IsType<ServerBootstrapper>(((ServerSupervisor) supervisor).Component);

var wrapper = ((ServerSupervisor) supervisor).Component;

Assert.IsType<AutomaticRetryServerComponentWrapper>(wrapper);
Assert.IsType<ServerBootstrapper>(((AutomaticRetryServerComponentWrapper)wrapper).InnerComponent);
}

[Fact]
Expand Down

0 comments on commit 193c698

Please sign in to comment.