add show crontab next 5 execution times
(cherry picked from commit 3a6b8bce14849516d4313427842a670b01903802)
This commit is contained in:
		
							parent
							
								
									4276a2c203
								
							
						
					
					
						commit
						6248546e4b
					
				| @ -1,8 +1,8 @@ | |||||||
| <script setup lang="ts"> | <script setup lang="ts"> | ||||||
| import cronstrue from 'cronstrue'; | import cronstrue from 'cronstrue'; | ||||||
| import { isValidCron } from 'cron-validator'; | import { isValidCron } from 'cron-validator'; | ||||||
| import { useStyleStore } from '@/stores/style.store'; |  | ||||||
| import { parseExpression } from 'cron-parser'; | import { parseExpression } from 'cron-parser'; | ||||||
|  | import { useStyleStore } from '@/stores/style.store'; | ||||||
| 
 | 
 | ||||||
| function isCronValid(v: string) { | function isCronValid(v: string) { | ||||||
|   return isValidCron(v, { allowBlankDay: true, alias: true, seconds: true }); |   return isValidCron(v, { allowBlankDay: true, alias: true, seconds: true }); | ||||||
| @ -96,15 +96,12 @@ const helpers = [ | |||||||
| function getLastExecutionTimes(cronExpression: string) { | function getLastExecutionTimes(cronExpression: string) { | ||||||
|   const interval = parseExpression(cronExpression); |   const interval = parseExpression(cronExpression); | ||||||
|   const times = []; |   const times = []; | ||||||
|    |  | ||||||
|   // Get the last five execution times |  | ||||||
|   for (let i = 0; i < 5; i++) { |   for (let i = 0; i < 5; i++) { | ||||||
|     times.push(interval.next().toJSON()); |     times.push(interval.next().toJSON()); | ||||||
|   } |   } | ||||||
|   return times; |   return times; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| 
 |  | ||||||
| const cronString = computed(() => { | const cronString = computed(() => { | ||||||
|   if (isCronValid(cron.value)) { |   if (isCronValid(cron.value)) { | ||||||
|     return cronstrue.toString(cron.value, cronstrueConfig); |     return cronstrue.toString(cron.value, cronstrueConfig); | ||||||
| @ -112,7 +109,6 @@ const cronString = computed(() => { | |||||||
|   return ' '; |   return ' '; | ||||||
| }); | }); | ||||||
| 
 | 
 | ||||||
| 
 |  | ||||||
| const executionTimesString = computed(() => { | const executionTimesString = computed(() => { | ||||||
|   if (isCronValid(cron.value)) { |   if (isCronValid(cron.value)) { | ||||||
|     const lastExecutionTimes = getLastExecutionTimes(cron.value); |     const lastExecutionTimes = getLastExecutionTimes(cron.value); | ||||||
| @ -146,7 +142,9 @@ const cronValidationRules = [ | |||||||
|       {{ cronString }} |       {{ cronString }} | ||||||
|     </div> |     </div> | ||||||
| 
 | 
 | ||||||
|     <div class="cron-execution-string">{{ executionTimesString }}</div> |     <div class="cron-execution-string"> | ||||||
|  |       {{ executionTimesString }} | ||||||
|  |     </div> | ||||||
| 
 | 
 | ||||||
|     <n-divider /> |     <n-divider /> | ||||||
| 
 | 
 | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user