Hangfire.RecurringJob [](https://www.nuget.org/packages/IeuanWalker.Hangfire.RecurringJob) [](https://www.nuget.org/packages/IeuanWalker.Hangfire.RecurringJob)
December 8, 2023 ยท View on GitHub
Automatically generates the recurring job registration code using source generators
How to use it?
- Install the NuGet package into your project.
Install-Package IeuanWalker.Hangfire.RecurringJob
- Add the
RecurringJobattribute to a class, and create anExecute()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();
}
}
- Register the recurring jobs
Once a
RecurringJobattribute has been added to a class in your project an extension method forIApplicationBuilderwill 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