Skip to main content

HangfireRecurringJob by Ieuan Walker

NuGet / site data

Nuget GitHub last commit GitHub Repo stars

Details

Info

info

Name: HangfireRecurringJob

This is a package that automatically generates the hangfire recurring jobs AddOrUpdate code, using source generators.

Author: Ieuan Walker

NuGet: https://www.nuget.org/packages/IeuanWalker.Hangfire.RecurringJob/

You can find more details at https://github.com/IeuanWalker/Hangfire.RecurringJob

Source: https://github.com/IeuanWalker/Hangfire.RecurringJob

Original Readme

note

Hangfire.RecurringJob Nuget Nuget

License: MIT Build

Automatically generates the recurring job registration code using source generators

How to use it?

  1. Install the NuGet package into your project.
Install-Package IeuanWalker.Hangfire.RecurringJob
  1. Add the RecurringJob attribute to a class, and create an Execute() method.
[RecurringJob]
public class RecurringJob1
{
public Task Execute()
{
throw new NotImplementedException();
}
}

[RecurringJob("* * * *")]
public class RecurringJob2
{
public void Execute()
{
throw new NotImplementedException();
}
}

[RecurringJob("* * * *", "Priority")]
public class RecurringJob3
{
public void Execute()
{
throw new NotImplementedException();
}
}

[RecurringJob]
[RecurringJob("*/5 * * * *", "GMT", "Priority", "DataRetention")]
public class RecurringJob4
{
public void Execute()
{
throw new NotImplementedException();
}
}
  1. Register the recurring jobs

    Once a RecurringJob attribute has been added to a class in your project an extension method for IApplicationBuilder will automatically be created. The extension method name convention is AddRecurringJobsFrom + your assembly name.

app.AddRecurringJobsFromExampleProject();

Example

Here is an example of what it looks like in use -

Left is the example code, and right is the generated code

image

About

note

Generating recurring jobs for Hangfire from class attribute

How to use

Example (source csproj, source files)

This is the CSharp Project that references HangfireRecurringJob

<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<InvariantGlobalization>true</InvariantGlobalization>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Hangfire.AspNetCore" Version="1.8.9" />
<PackageReference Include="Hangfire.Core" Version="1.8.9" />
<PackageReference Include="Hangfire.InMemory" Version="0.7.0" />
<!--<PackageReference Include="Hangfire.MemoryStorage" Version="1.8.0" />-->
<PackageReference Include="Hangfire.SqlServer" Version="1.8.9" />
<PackageReference Include="IeuanWalker.Hangfire.RecurringJob" Version="1.0.1" />
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="8.0.1" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.5.0" />
</ItemGroup>
<PropertyGroup>
<EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>
<CompilerGeneratedFilesOutputPath>$(BaseIntermediateOutputPath)\GX</CompilerGeneratedFilesOutputPath>
</PropertyGroup>
</Project>

Generated Files

Those are taken from $(BaseIntermediateOutputPath)\GX

namespace HangFireRec;

// <auto-generated/>

using Hangfire;
using Microsoft.AspNetCore.Builder;

public static class RecurringJobRegistrationExtensions
{
public static IApplicationBuilder AddRecurringJobsFromHangFireRec(this IApplicationBuilder app)
{
RecurringJob.AddOrUpdate<HangFireRec.MyNewJob>("MyNewJob", "default", x => x.Execute(), "*/1 * * * *", new RecurringJobOptions
{
TimeZone = TimeZoneInfo.FindSystemTimeZoneById("UTC")
});

return app;
}
}

Useful

Download Example (.NET C# )

Share HangfireRecurringJob

https://ignatandrei.github.io/RSCG_Examples/v2/docs/HangfireRecurringJob

In the same category (Hangfire) - 0 other generators