Skip to content

Commit

Permalink
Merge pull request #16 from ahydrax/update-deps
Browse files Browse the repository at this point in the history
Update for use with Hangfire 1.8
  • Loading branch information
ahydrax authored Jul 31, 2023
2 parents 9a1d93c + 6296e6f commit 1858e3f
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 25 deletions.
2 changes: 1 addition & 1 deletion src/Hangfire.Heartbeat/Hangfire.Heartbeat.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="HangFire.Core" Version="1.7.2" />
<PackageReference Include="HangFire.Core" Version="[1.7.2, 1.9)" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)'=='net462'">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<TargetFramework>net7.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<Folder Include="wwwroot\" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Hangfire" Version="1.7.2" />
<PackageReference Include="HangFire.Core" Version="1.7.2" />
<PackageReference Include="Hangfire.Redis.StackExchange" Version="1.8.0" />
<PackageReference Include="Hangfire" Version="1.8.4" />
<PackageReference Include="HangFire.Core" Version="1.8.4" />
<PackageReference Include="Hangfire.Redis.StackExchange" Version="1.9.0" />
</ItemGroup>

<ItemGroup>
Expand Down
42 changes: 22 additions & 20 deletions tests/Hangfire.Heartbeat.TestApplication/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using Hangfire.Dashboard;
using Hangfire.Heartbeat.Server;
using Hangfire.Redis;
using Hangfire.Redis.StackExchange;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
Expand All @@ -24,15 +25,12 @@ public Startup(IConfiguration configuration)

public void ConfigureServices(IServiceCollection services)
{
var storage = new RedisStorage("localhost:6379");

services.AddHangfire(configuration =>
configuration
.UseRedisStorage(Environment.GetEnvironmentVariable("REDIS"))
.UseStorage(storage)
.UseHeartbeatPage(TimeSpan.FromMilliseconds(500)));
}

public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
app.UseDeveloperExceptionPage();

var random = new Random();
var serverName = "Test server #" + random.Next(1, 1000);
Expand All @@ -42,20 +40,24 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
.Append(new ProcessMonitor(randomCheckInterval))
.ToArray();

app.UseHangfireServer(new BackgroundJobServerOptions
services.AddHangfireServer((sp, options) =>
{
ServerName = serverName,
ServerCheckInterval = TimeSpan.FromSeconds(5),
ServerTimeout = TimeSpan.FromSeconds(15),
HeartbeatInterval = TimeSpan.FromSeconds(3),
WorkerCount = 1
}, monitors);

app.UseHangfireDashboard("", new DashboardOptions { Authorization = new IDashboardAuthorizationFilter[0] });
RecurringJob.AddOrUpdate(() => Alloc(), Cron.Daily(), TimeZoneInfo.Utc);
RecurringJob.AddOrUpdate(() => CpuKill(75), Cron.Daily(), TimeZoneInfo.Utc);
RecurringJob.AddOrUpdate(() => GC.Collect(2), Cron.Daily(), TimeZoneInfo.Utc);
RecurringJob.AddOrUpdate(() => AggregateTest(), Cron.Daily(), TimeZoneInfo.Utc);
options.ServerName = serverName;
options.ServerCheckInterval = TimeSpan.FromSeconds(5);
options.ServerTimeout = TimeSpan.FromSeconds(15);
options.HeartbeatInterval = TimeSpan.FromSeconds(3);
options.WorkerCount = 1;
}, storage, monitors);
}

public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
app.UseDeveloperExceptionPage();
app.UseHangfireDashboard("", new DashboardOptions { Authorization = Array.Empty<IDashboardAuthorizationFilter>() });
RecurringJob.AddOrUpdate(nameof(Alloc), () => Alloc(), Cron.Daily());
RecurringJob.AddOrUpdate(nameof(CpuKill), () => CpuKill(75), Cron.Daily());
RecurringJob.AddOrUpdate(nameof(GC.Collect), () => GC.Collect(2), Cron.Daily());
RecurringJob.AddOrUpdate(nameof(AggregateTest), () => AggregateTest(), Cron.Daily());
}

public void AggregateTest()
Expand Down Expand Up @@ -92,7 +94,7 @@ public static void Alloc()
x[0].A = 1;
x[0].B = 1;
x[0].C = 1;
x[x.Length - 1].A = 2;
x[^1].A = 2;
if (w1.Elapsed > TimeSpan.FromSeconds(15))
{
break;
Expand Down

0 comments on commit 1858e3f

Please sign in to comment.