Skip to content

Commit

Permalink
Merge pull request #31460 from mkouba/scheduler-new-devui
Browse files Browse the repository at this point in the history
Scheduler - new Dev UI - first iteration
  • Loading branch information
phillip-kruger authored Mar 2, 2023
2 parents 41921fa + 662458a commit 0b8cb81
Show file tree
Hide file tree
Showing 13 changed files with 647 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
import io.quarkus.scheduler.common.runtime.AbstractJobDefinition;
import io.quarkus.scheduler.common.runtime.DefaultInvoker;
import io.quarkus.scheduler.common.runtime.ScheduledInvoker;
import io.quarkus.scheduler.common.runtime.ScheduledMethodMetadata;
import io.quarkus.scheduler.common.runtime.ScheduledMethod;
import io.quarkus.scheduler.common.runtime.SchedulerContext;
import io.quarkus.scheduler.common.runtime.SyntheticScheduled;
import io.quarkus.scheduler.common.runtime.util.SchedulerUtils;
Expand Down Expand Up @@ -183,7 +183,7 @@ public QuartzSchedulerImpl(SchedulerContext context, QuartzSupport quartzSupport
if (transaction != null) {
transaction.begin();
}
for (ScheduledMethodMetadata method : context.getScheduledMethods()) {
for (ScheduledMethod method : context.getScheduledMethods()) {
int nameSequence = 0;

for (Scheduled scheduled : method.getSchedules()) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package io.quarkus.scheduler.common.runtime;

import java.util.List;
import java.util.Objects;

import io.quarkus.scheduler.Scheduled;

public final class ImmutableScheduledMethod implements ScheduledMethod {

private final String invokerClassName;
private final String declaringClassName;
private final String methodName;
private final List<Scheduled> schedules;

public ImmutableScheduledMethod(String invokerClassName, String declaringClassName, String methodName,
List<Scheduled> schedules) {
this.invokerClassName = Objects.requireNonNull(invokerClassName);
this.declaringClassName = Objects.requireNonNull(declaringClassName);
this.methodName = Objects.requireNonNull(methodName);
this.schedules = List.copyOf(schedules);
}

public String getInvokerClassName() {
return invokerClassName;
}

public String getDeclaringClassName() {
return declaringClassName;
}

public String getMethodName() {
return methodName;
}

public List<Scheduled> getSchedules() {
return schedules;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@

import io.quarkus.scheduler.Scheduled;

public class ScheduledMethodMetadata {
// This class is mutable so that it can be serialized in a recorder method
public class MutableScheduledMethod implements ScheduledMethod {

private String invokerClassName;
private String declaringClassName;
Expand All @@ -19,10 +20,6 @@ public void setInvokerClassName(String invokerClassName) {
this.invokerClassName = invokerClassName;
}

public String getMethodDescription() {
return declaringClassName + "#" + methodName;
}

public String getDeclaringClassName() {
return declaringClassName;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package io.quarkus.scheduler.common.runtime;

import java.util.List;

import io.quarkus.scheduler.Scheduled;

/**
* Scheduled method metadata.
*
*/
public interface ScheduledMethod {

String getInvokerClassName();

String getDeclaringClassName();

String getMethodName();

List<Scheduled> getSchedules();

default String getMethodDescription() {
return getDeclaringClassName() + "#" + getMethodName();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public interface SchedulerContext {

CronType getCronType();

List<ScheduledMethodMetadata> getScheduledMethods();
List<ScheduledMethod> getScheduledMethods();

@SuppressWarnings("unchecked")
default ScheduledInvoker createInvoker(String invokerClassName) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@
import io.quarkus.scheduler.ScheduledExecution;
import io.quarkus.scheduler.Scheduler;
import io.quarkus.scheduler.common.runtime.DefaultInvoker;
import io.quarkus.scheduler.common.runtime.ScheduledMethodMetadata;
import io.quarkus.scheduler.common.runtime.MutableScheduledMethod;
import io.quarkus.scheduler.common.runtime.SchedulerContext;
import io.quarkus.scheduler.common.runtime.util.SchedulerUtils;
import io.quarkus.scheduler.runtime.SchedulerConfig;
Expand Down Expand Up @@ -279,7 +279,7 @@ public FeatureBuildItem build(SchedulerConfig config, BuildProducer<SyntheticBea
BuildProducer<GeneratedClassBuildItem> generatedClasses, BuildProducer<ReflectiveClassBuildItem> reflectiveClass,
AnnotationProxyBuildItem annotationProxy) {

List<ScheduledMethodMetadata> scheduledMetadata = new ArrayList<>();
List<MutableScheduledMethod> scheduledMetadata = new ArrayList<>();
ClassOutput classOutput = new GeneratedClassGizmoAdaptor(generatedClasses, new Function<String, String>() {
@Override
public String apply(String name) {
Expand All @@ -296,9 +296,9 @@ public String apply(String name) {
});

for (ScheduledBusinessMethodItem scheduledMethod : scheduledMethods) {
ScheduledMethodMetadata metadata = new ScheduledMethodMetadata();
MutableScheduledMethod metadata = new MutableScheduledMethod();
String invokerClass = generateInvoker(scheduledMethod, classOutput);
reflectiveClass.produce(new ReflectiveClassBuildItem(false, false, invokerClass));
reflectiveClass.produce(ReflectiveClassBuildItem.builder(invokerClass).constructors().methods().fields().build());
metadata.setInvokerClassName(invokerClass);
List<Scheduled> schedules = new ArrayList<>();
for (AnnotationInstance scheduled : scheduledMethod.getSchedules()) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package io.quarkus.scheduler.deployment.devui;

import java.util.List;

import io.quarkus.deployment.IsDevelopment;
import io.quarkus.deployment.annotations.BuildStep;
import io.quarkus.devui.spi.JsonRPCProvidersBuildItem;
import io.quarkus.devui.spi.page.CardPageBuildItem;
import io.quarkus.devui.spi.page.Page;
import io.quarkus.scheduler.deployment.ScheduledBusinessMethodItem;
import io.quarkus.scheduler.runtime.devui.SchedulerJsonRPCService;

public class SchedulerDevUIProcessor {

@BuildStep(onlyIf = IsDevelopment.class)
CardPageBuildItem page(List<ScheduledBusinessMethodItem> scheduledMethods) {

CardPageBuildItem pageBuildItem = new CardPageBuildItem("Scheduler");

pageBuildItem.addPage(Page.webComponentPageBuilder()
.icon("font-awesome-solid:clock")
.componentLink("qwc-scheduler-scheduled-methods.js")
.staticLabel(String.valueOf(scheduledMethods.size())));

return pageBuildItem;
}

@BuildStep(onlyIf = IsDevelopment.class)
JsonRPCProvidersBuildItem rpcProvider() {
return new JsonRPCProvidersBuildItem("Scheduler", SchedulerJsonRPCService.class);
}

}
Loading

0 comments on commit 0b8cb81

Please sign in to comment.