当前位置:网站首页>Using quartz under. Net core -- preliminary understanding of [2] operations and triggers

Using quartz under. Net core -- preliminary understanding of [2] operations and triggers

2022-04-23 17:10:00 Tomato Warrior

Catalog

1、 Key interfaces and classes

2、 What is? Quartz Homework in

3、 Job execution context

4、 Job unique ID

In the last one , We implemented a simple job scheduling , Next, we will have a preliminary understanding of Quartz Homework in (Job)


 

1、 Key interfaces and classes

  • IScheduler - The main way to interact with the scheduler API.
  • IJob - The interface implemented by the component you want the scheduler to execute .
  • IJobDetail - Used for definition Jobs Example .
  • ITrigger - A component that defines a schedule that will execute a given job , The job can have multiple associated triggers
  • JobBuilder - Used for definition / structure JobDetail example , This instance defines Jobs Example .
  • TriggerBuilder - Used for definition / Instance building triggers .
  • SchedulerBuilder - Used for definition / Build scheduler instance , need Quartz 3.1 Or later .

The above part is directly excerpted from the official website , Before you know the job , Let's familiarize ourselves with the above interfaces and classes , This is very helpful for the next study

 

2、 What is? Quartz Homework in

The job is to realize IJob The class of the interface , The interface has only one simple method :

namespace Quartz
{
    public interface IJob
    {
        Task Execute(JobExecutionContext context);
    }
}

Review our custom in the last article HelloJob, We did IJob Interface , And realize the unique Execute Method , That's it .

    public class HelloJob : IJob
    {
        public async Task Execute(IJobExecutionContext context)
        {
            await Console.Out.WriteLineAsync($"{DateTime.Now}");
        }
    }

 

3、 Job execution context

Execure In the method , Conveys a parameter ,IJobExecutionContext context

JobExecutionContext Contained in the  “ Runtime ” Information about the environment - Handle to the scheduler executing the job , Handle to trigger execution , Operational JobDetail object , And some other projects .

 

4、 Job unique ID

Review the code when creating the job in the previous section

 IJobDetail job = JobBuilder.Create<HelloJob>()
                .WithIdentity("job1", "jobGroup1")
                .Build();

Here we name our homework   job1, And assigned to jobGroup1 Group , Then the only identification of the job is separated by dots   "jobGroup1.job1"

The same is true for triggers

 

 

 

版权声明
本文为[Tomato Warrior]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204230553457897.html