From 56014e7c8fd724439e4a4a860d4b11bad8b6848f Mon Sep 17 00:00:00 2001 From: Manyanda Chitimbo Date: Sat, 2 Nov 2019 13:25:33 +0100 Subject: [PATCH] feat: add cron jobs in scheduler quickstart --- .../main/java/org/acme/scheduling/CounterBean.java | 14 +++++++++++++- .../src/main/resources/application.properties | 2 ++ 2 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 scheduler-quickstart/src/main/resources/application.properties diff --git a/scheduler-quickstart/src/main/java/org/acme/scheduling/CounterBean.java b/scheduler-quickstart/src/main/java/org/acme/scheduling/CounterBean.java index 146ea208e0..1550992d1f 100644 --- a/scheduler-quickstart/src/main/java/org/acme/scheduling/CounterBean.java +++ b/scheduler-quickstart/src/main/java/org/acme/scheduling/CounterBean.java @@ -5,6 +5,7 @@ import javax.enterprise.context.ApplicationScoped; import io.quarkus.scheduler.Scheduled; +import io.quarkus.scheduler.ScheduledExecution; @ApplicationScoped public class CounterBean { @@ -20,4 +21,15 @@ void increment() { counter.incrementAndGet(); } -} \ No newline at end of file + @Scheduled(cron="0 15 10 * * ?") + void cronJob(ScheduledExecution execution) { + counter.incrementAndGet(); + System.out.println(execution.getScheduledFireTime()); + } + + @Scheduled(cron = "{cron.expr}") + void cronJobWithExpressionInConfig() { + counter.incrementAndGet(); + System.out.println("Cron expression configured in application.properties"); + } +} diff --git a/scheduler-quickstart/src/main/resources/application.properties b/scheduler-quickstart/src/main/resources/application.properties new file mode 100644 index 0000000000..5aec70f127 --- /dev/null +++ b/scheduler-quickstart/src/main/resources/application.properties @@ -0,0 +1,2 @@ +cron.expr=*/5 * * * * ? +