Skip to content

A convenient way to create Quartz.NET jobs using attributes.

License

Notifications You must be signed in to change notification settings

fudiwei/Quartz.Extensions.JobAttribute

Repository files navigation

Quartz.Extensions.JobAttribute

GitHub Stars NuGet Version NuGet Download License

A convenient way to create Quartz.NET jobs using attributes.


Features

  • Supports scheduling jobs using QuartzJobAttribute instead of configuration files or programming.
  • Supports dependency injection in IJob class (depends on the library Quartz.Extensions.DependencyInjection).
  • Follows the lifecycle of ASP .NET Core.

Usage

Install it:

# Install by Package Manager
> Install-Package Quartz.AspNetCore
> Install-Package SKIT.Quartz.Extensions.JobAttribute

# Install by .NET CLI
> dotnet add package Quartz.AspNetCore
> dotnet add package SKIT.Quartz.Extensions.JobAttribute

Here is an example:

using Quartz;

[QuartzJob(Name = "Clocking", Description = "Tell the time every seconds.", CronExpression = "* * * * * ? ")]
public class ClockingJob : IJob
{
    private readonly ILogger _logger;

    public ClockingJob(ILoggerFactory loggerFactory)
    {
        _logger = loggerFactory.CreateLogger(GetType());
    }

    Task IJob.Execute(IJobExecutionContext context)
    {
        _logger.LogInformation("Now is " + context.FireTimeUtc);
        return Task.CompletedTask;
    }
}

Also, there are options for Name, Group, Description CronExpression, Priority, StoreDurably and RequestRecovery.

Then register service in ConfigureServices method in Startup.cs file.

using Quartz;

public void ConfigureServices(IServiceCollection services)
{
    services.AddQuartzJobs();

    services.AddQuartzServer(options =>
    {
        options.WaitForJobsToComplete = true;
    });
}

About

A convenient way to create Quartz.NET jobs using attributes.

Topics

Resources

License

Stars

Watchers

Forks

Languages