Skip to content

Commit 495e95e

Browse files
Boot on demand
1 parent 19d6b64 commit 495e95e

File tree

3 files changed

+19
-10
lines changed

3 files changed

+19
-10
lines changed

core/src/main/java/dev/vml/es/acm/core/event/EventDispatcher.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import dev.vml.es.acm.core.code.ExecutionHistory;
44
import dev.vml.es.acm.core.code.ExecutionQueue;
55
import dev.vml.es.acm.core.code.Executor;
6+
import dev.vml.es.acm.core.script.AutomaticScriptScheduler;
67
import dev.vml.es.acm.core.util.ResolverUtils;
78
import java.util.Collections;
89
import org.apache.sling.api.resource.LoginException;
@@ -29,6 +30,9 @@ public class EventDispatcher implements EventListener {
2930
@Reference
3031
private Executor executor;
3132

33+
@Reference
34+
private AutomaticScriptScheduler scriptScheduler;
35+
3236
@Reference
3337
private ResourceResolverFactory resourceResolverFactory;
3438

@@ -50,6 +54,9 @@ public void onEvent(Event event) {
5054
case HISTORY_CLEAR:
5155
doHistoryClear();
5256
break;
57+
case SCRIPT_SCHEDULER_BOOT:
58+
scriptScheduler.bootOnDemand();
59+
break;
5360
default:
5461
// not handled
5562
break;

core/src/main/java/dev/vml/es/acm/core/event/EventType.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55

66
public enum EventType {
77
EXECUTOR_RESET,
8-
HISTORY_CLEAR;
8+
HISTORY_CLEAR,
9+
SCRIPT_SCHEDULER_BOOT;
910

1011
public static Optional<EventType> of(String name) {
1112
return Arrays.stream(values())

core/src/main/java/dev/vml/es/acm/core/script/AutomaticScriptScheduler.java

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
import org.slf4j.LoggerFactory;
3535

3636
@Component(
37-
service = ResourceChangeListener.class,
37+
service = {ResourceChangeListener.class, AutomaticScriptScheduler.class},
3838
immediate = true,
3939
property = {
4040
ResourceChangeListener.PATHS + "=glob:" + ScriptRepository.ROOT + "/automatic/**/*.groovy",
@@ -54,12 +54,6 @@ public class AutomaticScriptScheduler implements ResourceChangeListener {
5454
description = "Schedules automatic scripts on instance up and script changes")
5555
public @interface Config {
5656

57-
@AttributeDefinition(
58-
name = "Boot Delay",
59-
description = "Time in milliseconds to delay the boot job execution"
60-
)
61-
long bootDelay() default 1000 * 10; // 10 seconds
62-
6357
@AttributeDefinition(
6458
name = "User Impersonation ID",
6559
description =
@@ -138,6 +132,14 @@ public void onChange(List<ResourceChange> changes) {
138132
}
139133
}
140134

135+
public void bootOnDemand() {
136+
LOG.info("Automatic scripts booting on demand - job scheduling");
137+
unscheduleBoot();
138+
scheduleBoot();
139+
LOG.info("Automatic scripts booting on demand - job scheduled");
140+
}
141+
142+
// TODO on AEMaaCS scheduler refuses to schedule job during activate
141143
private void bootWhenInstanceUp() {
142144
LOG.info("Automatic scripts booting on instance up - job scheduling");
143145
unscheduleBoot();
@@ -157,8 +159,7 @@ private void unscheduleBoot() {
157159
}
158160

159161
private void scheduleBoot() {
160-
Date bootDate = new Date(System.currentTimeMillis() + config.bootDelay());
161-
scheduler.schedule(bootJob(), configureScheduleOptions(BOOT_JOB_NAME, scheduler.AT(bootDate)));
162+
scheduler.schedule(bootJob(), configureScheduleOptions(BOOT_JOB_NAME, scheduler.NOW()));
162163
}
163164

164165
private ScheduleOptions configureScheduleOptions(String name, ScheduleOptions options) {

0 commit comments

Comments
 (0)