Hi all,
I'm trying to fully understand the cron-like expression for the AEM Sitemap Scheduler configuration.
On this page https://experienceleague.adobe.com/en/docs/experience-manager-learn/sites/seo/sitemaps#sitemap-sched... there is an example of:
"0 0 2 1/1 * ? *"
So trying to understand this documented example from left to right:
0 (first): Minute 0
0 (second): Hour 0, so together with the first 0 that means MIDNIGHT
2: Only run on the 2nd of the month
1/1: Every month - but why use 1/1 and not * here?
*: Any day of the week
?: I guess this means every year, but why not use * here?
* (last one): what is this for?
So in summary I'd like to understand why 1/1 and ? where used instead of *?
And what is that last * for?
Many thanks,
David
Solved! Go to Solution.
Views
Replies
Total Likes
hi @bosschaert, this expression schedules the job to run every day at 2:00 AM
The cron-like expression used in AEM's Sitemap Scheduler configuration follows the Quartz Scheduler format.
Field-by-field Explanation:
Seconds (0): The job triggers at the 0th second.
Minutes (0): The job triggers at the 0th minute.
Hours (2): The job triggers at 2 AM.
Day of Month (1/1): The job triggers every day (the 1/1 means start at day 1 and repeat every 1 day).
Month (*): The job triggers every month.
Day of Week (?): No specific value; used when the day of the month is specified to avoid conflicts.
Year (*): The job triggers every year.
hi @bosschaert, this expression schedules the job to run every day at 2:00 AM
The cron-like expression used in AEM's Sitemap Scheduler configuration follows the Quartz Scheduler format.
Field-by-field Explanation:
Seconds (0): The job triggers at the 0th second.
Minutes (0): The job triggers at the 0th minute.
Hours (2): The job triggers at 2 AM.
Day of Month (1/1): The job triggers every day (the 1/1 means start at day 1 and repeat every 1 day).
Month (*): The job triggers every month.
Day of Week (?): No specific value; used when the day of the month is specified to avoid conflicts.
Year (*): The job triggers every year.
Hi @giuseppebag thanks for the reply.
Ah so the first element is seconds rather than minutes - the documentation in https://experienceleague.adobe.com/en/docs/experience-manager-learn/sites/seo/sitemaps#sitemap-sched... links to https://cron.help/ which has minutes as the first element - so that documentation needs to be updated.
I found the https://www.quartz-scheduler.org/documentation/quartz-2.3.0/tutorials/crontrigger.html page with some info on the format and some explanation of ?, but still don't understand why 1/1 was specified instead of *?
Kind regards,
David
Views
Replies
Total Likes
For the month format, 1/1 is equivalent to *, which can be seen as a personal preference. The format X/Y can be helpful for defining different occurrences. For example, 3/2 can mean "every 2nd month starting in March," or in specific terms.
Views
Replies
Total Likes
Let's break down the cron-like expression for the AEM Sitemap Scheduler:
Expression:
0 0 2 1/1 * ? *
Parts, left to right:
Now to your specific questions:
TL;DR("Too Long; Didn't Read.):
Views
Replies
Total Likes
This answer is wrong in this context. The first argument is seconds as @giuseppebag correctly explained. Also you mention day-of-the week in 2 positions which is never correct.
Views
Replies
Total Likes
Hi @bosschaert ,
Expression Breakdown: 0 0 2 1/1 * ? *
What this Means in Practice:
Minute (0): The job triggers at the start of the hour exactly when the clock hits 00 minutes.
Hour (0): This triggers at midnight at the very beginning of the day.
Day of the Month (2): This means it runs only on the 2nd day of each month. So, it won’t trigger on the 1st or any other day only on the 2nd.
Month (1/1): The 1/1 means every month, starting from January. I’ve found this to be commonly used when you want to explicitly state that the job will run every month. It’s the same as using *, but using 1/1 can clarify intent (especially for those who might want to adjust it in the future, like changing it to 3/2 for "every 2nd month starting in March").
Day of Week (*): This wildcard means it doesn’t matter what day of the week it is the job will run on the 2nd of the month regardless of the day.
Day of Week (?): Here, we use ? to avoid ambiguity. When specifying the day of the month, we need to use ? in the day of the week field.
Year (*): This means the job runs every year no specific restriction on which year.
Why 1/1 and ?:
- The 1/1 in the month field is functionally the same as * but is often used for clarity. This way, it’s explicit that the task is meant to run every month starting from January.
The ? in the day of week field is required because we’ve already specified the day of the month. - In Quartz, you can’t have both a day of the month and day of the week specified without conflict, so one must be ?.
The Last * (Year):
- This is for specifying that the job will run every year, as the year field is optional in Quartz cron expressions. It’s just there to ensure the job isn't limited to a particular year.
Note:
While this expression will indeed schedule the job to run on the 2nd of every month at midnight, you’ll need to adjust it based on your specific use case. For example, if you want it to run on a different date, you just modify the day of the month (e.g., change the 2 to a 15 for the 15th). It’s all about customizing it based on when and how often you need the job to trigger.
Regards,
Amit
Views
Replies
Total Likes
This answer is wrong in this context. The first argument is seconds as @giuseppebag correctly explained. Also you mention day-of-the week in 2 positions which is never correct.
Views
Replies
Total Likes
Views
Likes
Replies
Views
Likes
Replies