Awesome
Hangfire.RecurringJob
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
RecurringJob
attribute 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
RecurringJob
attribute has been added to a class in your project an extension method forIApplicationBuilder
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