Skip to content

Hangfire Recurring Jobs ​

Sets up Hangfire and discovers recurring jobs from attributes, so a job's schedule lives next to the job class instead of being repeated in startup code. Storage defaults to in-memory and any Hangfire provider can be selected instead.

Job classes implement IRecurringJob, carry RecurringJobAttribute, and are scheduled through Hangfire's recurring job manager.

Categories ​

  • Configuration — per-environment overrides for what the attributes declare.
  • Extensions — startup extension methods for registering Hangfire and recurring jobs.
  • Attributes — metadata used to identify recurring job classes and cron expressions.
  • Services — the registry listing what was discovered.
  • Types — the contract application-defined recurring jobs implement.
  • Records — the metadata for one discovered job.
  • Constants — cron expressions for the common schedules.

Quick Example ​

csharp
using AlmightyShogun.Hangfire.RecurringJobs;
using Microsoft.Extensions.DependencyInjection;

builder.Services
    .AddCustomHangfire()
    .RegisterRecurringJobs(builder.Configuration);
csharp
using AlmightyShogun.Hangfire.RecurringJobs;

[RecurringJob("cleanup-expired-sessions", CronSchedules.Daily)]
public sealed class CleanupExpiredSessionsJob(
    SessionStore sessions
) : IRecurringJob
{
    public Task RunAsync(CancellationToken cancellationToken)
        => sessions.DeleteExpiredAsync(cancellationToken);
}
json
{
    "RecurringJobs": {
        "Jobs": {
            "cleanup-expired-sessions": {
                "Enabled": false
            }
        }
    }
}

All packages are released under the MIT License.