From e8019510e439e7b2bf81e5d2f714400443bd8901 Mon Sep 17 00:00:00 2001 From: musketyr Date: Tue, 12 Nov 2024 08:42:11 +0100 Subject: [PATCH] Wrap cron expression issues into appropriate exception to prevent crashing the application start up when the cron expression has wrong format --- .../com/agorapulse/worker/schedule/DefaultJobScheduler.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/libs/micronaut-worker/src/main/java/com/agorapulse/worker/schedule/DefaultJobScheduler.java b/libs/micronaut-worker/src/main/java/com/agorapulse/worker/schedule/DefaultJobScheduler.java index 1130d8d3..c6663e56 100644 --- a/libs/micronaut-worker/src/main/java/com/agorapulse/worker/schedule/DefaultJobScheduler.java +++ b/libs/micronaut-worker/src/main/java/com/agorapulse/worker/schedule/DefaultJobScheduler.java @@ -80,7 +80,11 @@ public void schedule(com.agorapulse.worker.Job job) { if (LOG.isDebugEnabled()) { LOG.debug("Scheduling cron job {} [{}] for {}", configuration.getName(), configuration.getCron(), job.getSource()); } - taskScheduler.schedule(configuration.getCron(), job); + try { + taskScheduler.schedule(configuration.getCron(), job); + } catch (IllegalArgumentException e) { + throw new JobConfigurationException(job, "Failed to schedule job " + configuration.getName() + " declared in " + job.getSource() + ". Invalid CRON expression: " + configuration.getCron(), e); + } } else if (configuration.getFixedRate() != null) { Duration duration = configuration.getFixedRate(); if (LOG.isDebugEnabled()) {