mirror of
https://github.com/CorentinTh/it-tools.git
synced 2025-05-04 05:19:12 -04:00
add show crontab next 5 execution times
(cherry picked from commit 3a6b8bce14849516d4313427842a670b01903802)
This commit is contained in:
parent
4276a2c203
commit
6248546e4b
1 changed files with 7 additions and 9 deletions
|
@ -1,8 +1,8 @@
|
|||
<script setup lang="ts">
|
||||
import cronstrue from 'cronstrue';
|
||||
import { isValidCron } from 'cron-validator';
|
||||
import { useStyleStore } from '@/stores/style.store';
|
||||
import { parseExpression } from 'cron-parser';
|
||||
import { useStyleStore } from '@/stores/style.store';
|
||||
|
||||
function isCronValid(v: string) {
|
||||
return isValidCron(v, { allowBlankDay: true, alias: true, seconds: true });
|
||||
|
@ -22,7 +22,7 @@ const helpers = [
|
|||
{
|
||||
symbol: '*',
|
||||
meaning: 'Any value',
|
||||
example: '* * * *',
|
||||
example: '* * * *',
|
||||
equivalent: 'Every minute',
|
||||
},
|
||||
{
|
||||
|
@ -96,15 +96,12 @@ const helpers = [
|
|||
function getLastExecutionTimes(cronExpression: string) {
|
||||
const interval = parseExpression(cronExpression);
|
||||
const times = [];
|
||||
|
||||
// Get the last five execution times
|
||||
for (let i = 0; i < 5; i++) {
|
||||
times.push(interval.next().toJSON());
|
||||
}
|
||||
return times;
|
||||
}
|
||||
|
||||
|
||||
const cronString = computed(() => {
|
||||
if (isCronValid(cron.value)) {
|
||||
return cronstrue.toString(cron.value, cronstrueConfig);
|
||||
|
@ -112,12 +109,11 @@ const cronString = computed(() => {
|
|||
return ' ';
|
||||
});
|
||||
|
||||
|
||||
const executionTimesString = computed(() => {
|
||||
if (isCronValid(cron.value)) {
|
||||
const lastExecutionTimes = getLastExecutionTimes(cron.value);
|
||||
const executionTimesString = lastExecutionTimes.join('\n');
|
||||
return `Next 5 execution times:\n${executionTimesString}`;
|
||||
const executionTimesString = lastExecutionTimes.join('\n');
|
||||
return `Next 5 execution times:\n${executionTimesString}`;
|
||||
}
|
||||
return ' ';
|
||||
});
|
||||
|
@ -146,7 +142,9 @@ const cronValidationRules = [
|
|||
{{ cronString }}
|
||||
</div>
|
||||
|
||||
<div class="cron-execution-string">{{ executionTimesString }}</div>
|
||||
<div class="cron-execution-string">
|
||||
{{ executionTimesString }}
|
||||
</div>
|
||||
|
||||
<n-divider />
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue