Quartz.net Configuration

Source: Internet
Author: User
Tags xml example

Quartz.net is an open-source job scheduling framework, which is a. NET migration of the Opensymphony Quartz API, written in C # that can be used in WinForm and ASP. It provides a great deal of flexibility without sacrificing simplicity. You can use it to create simple or complex schedules for executing a job. It has many features, such as database support, clustering, plugins, support for cron-like expressions, and so on.

First look at the simple Quartz_jobs.xml example

<?XML version= "1.0" encoding= "UTF-8"?>  <!--This file contains job definitions in schema version 2.0 format -  <Job-scheduling-dataxmlns= "Http://quartznet.sourceforge.net/JobSchedulingData"Xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance"version= "2.0">    <processing-directives>     <Overwrite-existing-data>True</Overwrite-existing-data>   </processing-directives>    <Schedule>      <Job>         <name>Samplejob</name>         <Group>Samplegroup</Group>         <Description>Sample Job for Quartz Server</Description>         <Job-type>Quartz.Server.SampleJob, Quartz.server</Job-type>         <Durable>True</Durable>         <Recover>False</Recover>     </Job>     <Trigger>       < Simple>         <name>Samplesimpletrigger</name>         <Group>Samplesimplegroup</Group>         <Description>Simple trigger to simply fire sample job</Description>         <Job-name>Samplejob</Job-name>         <Job-group>Samplegroup</Job-group>         <misfire-instruction>Smartpolicy</misfire-instruction>         <Repeat-count>-1</Repeat-count>         <Repeat-interval>10000</Repeat-interval>       </ Simple>     </Trigger>      <Job>       <name>Commissionjob</name>       <Group>Commissionjob</Group>       <Description>Sample Job for Quartz Server</Description>       <Job-type>Settlement.Jobs.CommissionJob, Settlement.jobs</Job-type>       <Durable>True</Durable>       <Recover>False</Recover>     </Job>      <Trigger>       <Cron>         <name>SampleSimpleTrigger2</name>         <Group>SampleSimpleTrigger2</Group>         <Job-name>SampleJob2</Job-name>         <Job-group>SampleGroup2</Job-group>         <cron-expression>0/10 * * * *?</cron-expression>       </Cron>     </Trigger>   </Schedule> </Job-scheduling-data>

Job-scheduling-data is no longer explained with the node

Processing-directives This node is the official example of the existence, do not have a deep understanding of what to do, to maintain the default configuration can be

Schedule Task Scheduling collection can configure multiple but seemingly only the first configuration to work, how to make multiple schedule at the same time want to know the children's shoes to tell under, greatly appreciated. All job and trigger are placed under this node.

Job task, in fact, is the 1.x version of the <JOB-DETAIL>, this node is used to define each specific task, multiple tasks Please create multiple job nodes to

  • Name (required), the names of multiple jobs in the same group cannot be the same, and if group is not set, all job without group is the same group, such as:<name>samplejob</name>
  • Group (optional) tasks belong to groups that identify the groups to which the task belongs, such as:<group>samplegroup</group>
  • Description (optional) task description, which describes the specific contents of the task, such as: <description>sample job for Quartz server</description>
  • Job-type (required) task type, the specific type of task and its owning assembly, format: the class name that implements the Ijob interface that contains the full namespace, the assembly name, such as: <job-type>quartz.server.samplejob, Quartz.server</job-type>
  • Durable (optional) The specific function is not known, the official example defaults to true, such as:<durable>true</durable>
  • Recover (optional) The specific role is not known, the official example defaults to false, such as:<recover>false</recover>


    Trigger task triggers, which define the way a job is used, the same job can define multiple trigger, and multiple trigger perform schedules independently of each other, and each trigger must define only one type of trigger ( Calendar-interval, simple, cron)

    Calendar-interval a type of trigger, used less, is skipped here

    Simple task trigger, which can dispatch tasks for repetitive execution

      • Name (required) trigger names, names must be different in the same group
      • Group (optional) Trigger groups
      • Description (optional) trigger description
      • Job-name (required) The task name to be dispatched, the job-name must be exactly the same as the name in the corresponding job node
      • Job-group (optional) the group to which the dispatch task (Job) belongs, which must be exactly the same as the group in the job
      • Start-time (optional) task start execution time UTC time, Beijing time needs +08:00, such as:<start-time>2012-04-01t08:00:00+08:00</start-time> Indicates that the property will be detected when the service starts or restarts on April 1, 2012 8:00, and if this property is not set or the Start-time setting is earlier than the current time, the schedule is executed immediately after the service starts. If the set time is later than the current time, the service will wait for the same set time before the first execution of the task, generally without special needs please do not set this property
      • Repeat-count (required) The number of task executions, such as:<repeat-count>-1</repeat-count> for unlimited execution, <repeat-count>10</ Repeat-count> represents 10 executions
      • Repeat-interval (required) task trigger interval (milliseconds), such as:<repeat-interval>10000</repeat-interval> executed every 10 seconds

    Cron Complex task trigger-customizing task scheduling with Cron expressions (highly recommended)

      • Name (required) trigger names, names must be different in the same group
      • Group (optional) Trigger groups
      • Description (optional) trigger description
      • Job-name (required) The task name to be dispatched, the job-name must be exactly the same as the name in the corresponding job node
      • Job-group (optional) the group to which the dispatch task (Job) belongs, which must be exactly the same as the group in the job
      • Start-time (optional) task start execution time UTC time, Beijing time needs +08:00, such as:<start-time>2012-04-01t08:00:00+08:00</start-time> Indicates that the property will be detected when the service starts or restarts on April 1, 2012 8:00, and if this property is not set, the service performs a task schedule based on the Cron-expression settings, and if the Start-time is set earlier than the current time, After the service starts, it ignores the cron-expression setting, executes the dispatch immediately , and then executes the task schedule according to Cron-expression, if the time is set later than the current time, The service will be the same after the set time to apply cron-expression, according to the rules to perform task scheduling, generally without special needs please do not set this property
      • Cron-expression (required) cron expression, such as: <CRON-EXPRESSION>0/10 * * * * *?</cron-expression> every 10 seconds

    After understanding the Quartz_jobs.xml configuration of Quartz.net 2.0, you can reference the Quartz.dll file in your project and implement the Ijob interface, flexibly configure quartz_jobs according to the needs of the actual project, no additional development is required, To realize flexible multi-task scheduling, it is necessary to note that the modified Quartz_ Jobs.xml the file, the Quartz service will not reload the file by default, to allow the modified file to take effect need to restart the service before the line, in addition Start-time properties please use caution, if you really need to be able to delete the property immediately after use can cause very serious consequences (firsthand experience the lessons of blood, hehe )

The cron expressions of quartz are sequentially
Seconds (0~59)
Minutes (0~59)
Hours (0~23)
Days (months) (0~31, but you need to consider the number of days of your month)
Month (0~11)
Days (weeks) (1~7 1=sun or Sun,mon,tue,wed,thu,fri,sat)
7. Year (1970-2099)

Each of these elements can be a value (such as 6), a continuous interval (9-12), a time interval (8-18/4) (/= every 4 hours), a list (1,3,5), and a wildcard character. Because the "date in the month" and "date in the week" are mutually exclusive, one of the two elements must be set.
0 0 10,14,16 * *? 10 o'clock in the morning, 2 o'clock in the afternoon, 4 O ' Day
0 0/30 9-17 * *? Every half hour for nine to five working hours
0 0 12? * WED means every Wednesday noon 12 o'clock
Some sub-expressions can contain ranges or lists
For example: subexpression (Day (week)) can be "Mon-fri", "Mon,wed,fri", "Mon-wed,sat"
The "*" character represents all possible values
Therefore, "*" in the sub-expression (month) represents the meaning of each month, "*" in the subexpression (Day (week)) represents every day of the week

The "/" character is used to specify the increment of the numeric value
For example: "0/15" in sub-expressions (minutes) means starting from the No. 0 minute, every 15 minutes
"3/20" in the sub-expression (minutes) means that every 20 minutes (it is the same as "3,23,43") starting from the 3rd minute

“? "Character is used only for days (months) and days (weeks) of two sub-expressions, indicating that no value is specified
When one of the 2 sub-expressions is assigned a value, in order to avoid a conflict, you need to set the value of another subexpression to "? ”

The "L" character is used only for days (months) and days (weeks) of two sub-expressions, which is the abbreviation for the word "last"
But it has a different meaning in two sub-expressions.
In the day (month) subexpression, "L" represents the last day of the one-month
In the day (week) Self-expression, "L" represents the last day of one weeks, the SAT
If there is something specific before "L", it has other meanings.
For example: "6L" means the 6th day of the month, and "Fril" means the last Friday of the month.
Note: When using the "L" parameter, do not specify a list or range, as this can cause problems



Attached: cronexpression configuration Instructions

Special characters allowed for field allowed values
Seconds 0-59,-*/
Sub 0-59,-*/
Hours 0-23,-*/
Date 1-31,-*? /L W C
Month 1-12 or JAN-DEC,-*/
Week 1-7 or Sun-sat,-*? /L C #
Year (optional) leave blank, 1970-2099,-*/
Meaning of an expression
"0 0 12 * *?" trigger 12 o'clock noon every day.
"0 15 10?" * * "trigger 10:15 every day"
"0 15 10 * *?" Daily 10:15 Trigger
"0 15 10 * *?" * "10:15 per day" trigger
"0 15 10 * *?" 2005 "2005-year daily 10:15 Trigger
"0 * 14 * *?" triggers every 1 minutes from 2 o'clock in the afternoon to 2:59 daily
"0 0/5 14 * *?" triggers every 5 minutes from 2 o'clock in the afternoon to 2:55 daily
"0 0/5 14,18 * *?" triggers every 5 minutes from 2 o'clock in the afternoon to 2:55 daily and from 6 o'clock in the afternoon to 6:55
"0 0-5 14 * *?" triggers every 1 minutes from 2 o'clock in the afternoon to 2:05 daily
"0 10,44 14?" 3 WED "2:10 and 2:44 triggers in Wednesday of every March
"0 15 10?" * Mon-fri "Monday to Friday 10:15 trigger
"0 15 10 15 *?" 15th 10:15 per month
"0 L *?" 10:15 on the last day of the month
"0 15 10?" * 6L "Last month of Friday 10:15 Trigger
"0 15 10?" * 6L 2002-2005 "2002 to 2005 the last of the monthly Friday 10:15 trigger
"0 15 10?" * 6#3 "Monthly third Friday 10:15 trigger
Special character meaning
* denotes all values;
? Represents a value that is not stated, that is, not concerned about its value;
-Represents a specified range;
, which indicates that a possible value is attached;
/symbol indicates the start time, and the symbol indicates the value increment each time;
L ("last") "L" is used in the Day-of-month field meaning "the final day of the month"; In the Day-of-week field, it simply means "7" or "SAT". If used in conjunction with a number in the Day-of-week field, it means "the last one weeks of the month" – for example: "6L" means "last Friday of the month". When we use "L", it is important not to specify a list value or range, otherwise we will get some unexpected results.
W ("weekday") can only be used in the Day-of-month field. Used to describe the working day closest to the specified day (Monday to Friday). For example: In the Day-of-month field with "15W" means "closest to the 15th day of the month", that is, if the 15th day of the month is Saturday, then the trigger will be triggered on the 14th day of the month, Friday, if the 15th day is Sunday, then the trigger will be triggered in the month 16th day that Monday If the 15th day of the month is Tuesday, trigger this day on the trigger. Note that this usage only calculates the value in the current month and does not cross the current month. The "W" character can only be specified one day in Day-of-month and cannot be a range or list. You can also use "LW" to specify the last working day of the month.
# can only be used in the Day-of-week field. Used to specify the first few weeks of the month. Example: In the Day-of-week field "6#3" means the 3rd Friday of this month (6 means Friday, 3 refers to 3rd). If the specified date does not exist, the trigger is not triggered.
C refers to the calculated value after contacting the calendar. Example: In the Day-of-month field, "5C" means the first day of the calendar including the 5th day of the month, or the first day in the Day-of-week field that includes the calendar after this Sunday or later.

Cron expressions are used to configure Crontrigger instances. A cron expression is a string that consists of 7 sub-expressions. Each sub-expression describes a separate schedule detail. These sub-expressions are separated by spaces, respectively:

1. Seconds sec

2. Minutes minutes

3. Hours hours

4. Days of the Day-of-month month

5 month

6. Day-of-week Days of the week

7. Year (optional field) (optional field)

The example string for a cron expression is "0 0 12?" * WED ", which means" 12:00 noon every Wednesday ".

A single child expression can contain a range or a list. For example: The days of the week in the previous example this field (here is "WED") can be replaced with "Mon-fri", "MON, WED, FRI" or even "Mon-wed,sat".

The wildcard character (' * ') can be used to represent "each" possible value in a domain. Therefore, the * in the month field represents each month, while the * in the Day-of-week field represents "Every day of the week".

All of the values in the domain have a specific legal scope, the legal range of these values is quite obvious, for example: the legal value of the second and the domain is 0 to 59, the legal range of the hour is 0 to 23,day-of-month is worth legal where the range is 0 to 31, but you need to be aware of the different days in different months. The legal value for the month is 0 to 11. or use the string Jan,feb MAR, APR, May, June, JUL,, SEP, OCT, NOV and Dec to indicate. Days-of-week can be expressed in 1 to 7来 (1= Sunday) or in string Sun, MON, TUE, WED, THU, FRI, and Sat.

The '/' character is used to denote the increment of the value, for example, if the minute field is placed in ' 0/15 ', it means "every 15 minutes, starting from 0", if you use ' 3/20 ' in the minute field, it means "every 20 minutes in the hour, starting from the 3rd minute" or the other same form is ' 3,23,43 '.

‘?‘ Characters can be used in day-of-month and Day-of-week domains, which are used to denote "no value specified". This is useful when you need to specify a value for one or two fields without having to set up other domains.

The ' L ' character can be used in Day-of-month and Day-of-week, which is a shorthand for "last", but has a different meaning in two domains. For example, the "L" in the Day-of-month field represents the last day of the month, that is, 31st of January, non-leap year February of 28th. If it is used in day-of-week, it means "7" or "SAT". However, if the character is followed by a different value in the Day-of-week field, the last week of the month is xxx. For example: "6L" or "Fril" represents the last Friday of this month. When using the ' L ' option, the most important thing is not to specify a list or range of values, which can cause confusion.

The ' W ' character is used to specify the closest week (specified in the Day-of-week field) to the nearest day of the day. For example: If you specify "15W" for the Day-of-month field, it means "the nearest week of the month 15th".

' # ' represents the first few weeks of the month. For example: "6#3" or "fri#3" in the Day-of-week field means "third Friday of the month".

As an example, the following quartz.net cloning expression will execute a job 10:15 A.M. every day from Monday to Friday.

0 15 10? * Mon-fri

The following expression

0 15 10? * 6L 2007-2010

The job will be executed in the last Friday 10:15 A.M. of each month from 2007 to 2010. You can't use Simpletrigger to do these things. You can use either of the two, but whichever is appropriate depends on your scheduling needs.

Quartz.net Configuration

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.