ABC document, Chinese Document
Document directory
Content of this section:
- Introduction
- Install
- Create a job
- Scheduling
- More
Introduction
Quartz is a fully functional open-source work scheduling system that can be used for minimal application to a large enterprise system. The. Abp. Quartz package can be used to integrate Quartz into the ABP.
If you have a higher scheduling requirement, Quzrtz is a good choice, hangfire is also a good choice for queues for persistent background work.
Install
SetAbp. Quartz Install the nuget package in your project andAbpQuartzModuleAddDependsOnFeatures:
[DependsOn(typeof (AbpQuartzModule))]public class YourModule : AbpModule{ //...}
Create a job
To create a new job, you must either implement the IJob interface of Quartz or inherit from the JobBase class (defined in. in the Quartz package), JobBase has some helpful attributes and methods (such as logging and localization). A simple Job class is as follows:
public class MyLogJob : JobBase, ITransientDependency{ public override void Execute(IJobExecutionContext context) { Logger.Info("Executed MyLogJob :)"); }}
The Execute method is implemented by logging. For more information, see the Quartz document.
Scheduling
UseIQuartzScheduleJobManagerTo schedule the work, inject it into your class (or parse its instance in your module's PostInitialize method and then use it) to schedule the work. for example, you can use a controller to schedule a job:
public class HomeController : AbpController{ private readonly IQuartzScheduleJobManager _jobManager; public HomeController(IQuartzScheduleJobManager jobManager) { _jobManager = jobManager; } public async Task<ActionResult> ScheduleJob() { await _jobManager.ScheduleAsync<MyLogJob>( job => { job.WithIdentity("MyLogJobIdentity", "MyGroup") .WithDescription("A job to simply write logs."); }, trigger => { trigger.StartNow() .WithSimpleSchedule(schedule => { schedule.RepeatForever() .WithIntervalInSeconds(5) .Build(); }); }); return Content("OK, scheduled!"); }}
More
For more information about Quartz, see its documentation.
Original ENGLISH