当前位置:网站首页>Quartz. Net c tutorial - course 4: triggers
Quartz. Net c tutorial - course 4: triggers
2022-07-21 22:20:00 【changtianshuiyue】
and jobs equally , triggers It's easy to use , But there are also some customized options to understand , Otherwise, it is difficult to give full play Quartz.NET The function of . in addition , There are also many different types trigger, It can meet all kinds of scheduling demand .
Common Trigger Attributes
be-all trigger class , Except for one TriggerKey properties , There are other common attributes . These attribute values are constructed trigger definition It's time for TriggerBuilder To assign a value ( The following example will introduce ).
Common property :
- JobKey: stay trigger When triggered , For unique indication trigger object .
- StartTimeUtc: Indicates when to trigger First scheduling . Its value is a DateTimeOffset object , Defines a time on the calendar . There are some trigger type , trigger Will trigger at the beginning , other trigger A scheduler start time will be marked . That means you can give trigger A scheduling time , similar : " The fifth day of January " , If StartTimeUtc The value of is 4 month 1 Number , Then we have to wait for months trigger Will trigger .
- EndTimeUtc: Indicate when to start trigger Don't be dispatched again . in other words If trigger The scheduling time is Every month on the fifth , And EndTimeUtc The value is 7 month 1 Number , So this trigger The last execution time of is 6 month 5 Number .
Other properties are discussed in detail below .
Priority
If it's in your Quartz.NET There are several working threads in the thread pool , Quartz.NET There may not be enough resources to immediately execute trigger. At this time, you need to control Quartz.NET When there are idle worker threads , Which one? trigger Will get execution time . This needs to be given trigger set priority . If you don't set priorities , So the default value is 5, Any integer value can be set on the priority , Integer or negative number is ok .
Be careful : The value of priority is only executed at the same time trigger It works . The scheduling time is early trigger Regardless of the priority, it will be later than the scheduling time trigger Execute first .
Be careful : When one trigger It is detected that it needs to be restored , Then its priority will be restored to the same as the previous priority .
Misfire Instructions
misfire It means a trigger Because his scheduler was turned off, he missed its trigger time , Or because of Quartz.NET There are no available threads in the thread pool to execute trigger Of job. Different trigger Types have their own misfire Indicator . The default with 'smart policy' Indicator - It will be based on trigger Type and configuration to dynamically determine its own behavior . When the scheduler starts
, It looks for all missed triggers triggers, Then update according to their respective configured indicators triggers.
Calendars
Quartz.NET Calendar Object implementation ICalendar Interface , stay trigger When stored in the scheduler, it will interact with trigger Connect . Calendars Can be used from trigger Move a specific time block out of the trigger period of . for example , You have one. trigger In the morning of every working day 9:30, And then I added a Calendar To remove all holidays .
Calendar It can be any implementation ICalendar Serializable object of interface , The interface is as follows :
namespace Quartz
{
public interface ICalendar
{
string Description {
get; set; }
ICalendar CalendarBase {
set; get; }
bool IsTimeIncluded(DateTimeOffset timeUtc);
DateTime GetNextIncludedTimeUtc(DateTimeOffset timeUtc);
}
}
although calendarEven You can move out of periods as small as milliseconds , At that time, you may want to move out of the whole day , For convenience , Quartz.NET Defined a HolidayCalendar class .
Calendars Must be initialized and used AddCalendar() Sign up to scheduler. about HolidayCalendar, After initialization , You need to use it AddExcludedDate(DateTime date) Method to fill in the date you want to move out . The same calendar Objects can be given to multiple triggers Use :
Calendar Example
HolidayCalendar cal = new HolidayCalendar();
cal.AddExcludedDate(someDate);
sched.AddCalendar("myHolidays", cal, false);
ITrigger t = TriggerBuilder.Create()
.WithIdentity("myTrigger")
.ForJob("myJob")
.WithSchedule(CronScheduleBuilder.DailyAtHourAndMinute(9, 30)) // execute job daily at 9:30
.ModifiedByCalendar("myHolidays") // but not on holidays
.Build();
// .. schedule job with trigger
ITrigger t2 = TriggerBuilder.Create()
.WithIdentity("myTrigger2")
.ForJob("myJob2")
.WithSchedule(CronScheduleBuilder.DailyAtHourAndMinute(11, 30)) // execute job daily at 11:30
.ModifiedByCalendar("myHolidays") // but not on holidays
.Build();
// .. schedule job with trigger2
The next lesson introduces triggers Structural details of . Now? , Just know that the above code constructs two trigger, Each is scheduled to execute every day . however calendar It will make them skip the scheduling time .
You can see Quartz.Impl.Calendar Is there anything in the namespace that meets your needs ICalendar Realization .
边栏推荐
- Sonova sonova reduced the time of compliance documents by 80% using polarion
- 华为liteos内存管理源码以及架构分析
- 物联网由哪些部分组成?
- 物联网设备的分类及未来发展中存在的问题有哪些?
- 物联网给企业的发展带来了哪些影响?
- 带您了解无线充电技术的现状和未来发展趋势
- 西门子邀您参加7月27日ALM网络研讨会
- 什么是直饮机?它的工作原理和优点是什么?
- 数字化转型 | 壳牌采用Polarion软件,对资本项目数据进行数字化、流程化处理
- Healthcare technology innovators use polarion software to reduce test creation time by up to 75%
猜你喜欢
一起学习gcc gdb makefile
重磅:国产IDE发布,由阿里研发,完全开源了(高性能+高定制性)
Raspberry pie 4B sound sensor do module
About the understanding of automated testing: purpose and essence! (must see for beginners)
Label Embedding Online Hashing for Cross-Modal Retrieval
使用 KubeKey 搭建 Kubernetes/KubeSphere 环境的“心路(累)历程“
Do you know how to build data-driven, keyword driven and hybrid selenium framework
[ALM] Introduction to the demand management solution of polaron ALM
JMeter中如何实现接口之间的关联?
How the ALM system manages objects through containers (take polarion as an example)
随机推荐
Réponse: Qu'est - ce que l'unit é de concept nmn et qu'est - ce que nmn exactement
Liteos connector script (I)
Hexadecimal conversion
什么是PCBA?PCBA测试的重要性有哪些?
Li Mu's learning notes of hands-on learning in depth (4) Chapter 1 preparatory knowledge section 2 data preprocessing
Learning notes of Li Mu's "hands on learning deep learning" (5) Chapter 1 preparatory knowledge section 3 linear algebra
Realize the function of memcpy by yourself
JMeter中如何实现接口之间的关联?
Polarion gives and takes -- aspice game between OEMs and suppliers
liteos连接器脚本(二)
Basic process of APP testing and key points of APP testing
12 solutions d'optimisation SQL super pratiques
DevStream 成为 CNCF Sandbox 项目啦!- 锣鼓喧天、鞭炮齐鸣、红旗招展、忘词了。
JMeter advanced performance test response results are saved locally
nmn有什么不好的作用吗,深剖nmn的功效与作用
一起学习SCP NFS TFTP
Qt5 GUI
Appium+Pytest+Allure实现APP自动化测试,小试牛刀
Understand ALM polarion from T-type talents
网关是什么?什么是物联网网关?