I\'m trying to get a cron job working within a legacy Java/Spring/Hibernate project, so I decided to use the spring scheduler.
I want myTask.doStuff to run at 12:00
Taking some note from: https://www.baeldung.com/cron-expressions
1 2 3 4 5 6 Index
- - - - - -
* * * * * * command to be executed
- - - - - -
| | | | | |
| | | | | ------- Day of week (MON - SUN)
| | | | --------- Month (1 - 12)
| | | ----------- Day of month (1 - 31)
| |-------------- Hour (0 - 23)
| --------------- Minute (0 - 59)
----------------- Seconds (0 - 59)
From: https://www.cyberciti.biz/faq/how-do-i-add-jobs-to-cron-under-linux-or-unix-oses/
1 2 3 4 5 Index
- - - - -
* * * * * command to be executed
- - - - -
| | | | |
| | | | ----- Day of week (0 - 7) (Sunday=0 or 7)
| | | ------- Month (1 - 12)
| | --------- Day of month (1 - 31)
| ----------- Hour (0 - 23)
------------- Minute (0 - 59)
Side note:
*/5 * * * * Linux cron job0 */5 * * * * Spring schedule tasksShow code snippetRun Code snippet$('.select2').select2({
width: '100%'
});
//// Init ////////////
$dropdown = $("#secondsSelect");
for (let i = 1; i < 60; i++) {
$dropdown.append($("").val(i).text(i));
}
$dropdown = $("#minSelect");
for (let i = 1; i < 60; i++) {
$dropdown.append($("").val(i).text(i));
}
$dropdown = $("#hoursSelect");
for (let i = 1; i < 24; i++) {
$dropdown.append($("").val(i).text(i));
}
$dropdown = $("#dayOfMonthSelect");
for (let i = 1; i < 32; i++) {
$dropdown.append($("").val(i).text(i));
}
//// Init End ////////////
$('.select2').on('select2:select', function(e) {
let value = e.params.data.id;
let prevValue = $(this).val().length > 0 ? $(this).val()[0] : null;
if (value != parseInt(value)) {
$(this).val(value).change();
} else if (prevValue != parseInt(prevValue)) {
$(this).val(value).change();
}
calculateSpringCron();
});
let r = function(dropdown) {
return dropdown.val().join(",");
}
let calculateSpringCron = function() {
let result = [
r($("#secondsSelect")),
r($("#minSelect")),
r($("#hoursSelect")),
r($("#dayOfMonthSelect")),
r($("#monthsSelect")),
r($("#weekdaySelect")),
];
$("#result").val(result.join(" "));
$("#result-expand").html(result.join(" "))
}
calculateSpringCron();
.ms-container {
display: flex;
flex-direction: column;
width: 100%;
padding-left: 3em;
padding-right: 3em;
background: none !important;
padding-bottom: 5em;
}
Spring Schedule Cron Generator
Seconds:
Minutes:
Hours:
Days of month:
Months:
Weekday:
Result:
With a bit of seperation for better viewing: