Skip to content

Commit a0a24e4

Browse files
Fmt
1 parent 1ab408e commit a0a24e4

File tree

1 file changed

+32
-20
lines changed

1 file changed

+32
-20
lines changed

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

Lines changed: 32 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,11 @@
4747
service = {ResourceChangeListener.class, EventListener.class, JobConsumer.class},
4848
immediate = true,
4949
property = {
50-
ResourceChangeListener.PATHS + "=glob:" + ScriptRepository.ROOT + "/automatic/**/*.groovy",
51-
ResourceChangeListener.CHANGES + "=ADDED",
52-
ResourceChangeListener.CHANGES + "=CHANGED",
53-
ResourceChangeListener.CHANGES + "=REMOVED",
54-
JobConsumer.PROPERTY_TOPICS + "=" + ScriptScheduler.JOB_TOPIC
50+
ResourceChangeListener.PATHS + "=glob:" + ScriptRepository.ROOT + "/automatic/**/*.groovy",
51+
ResourceChangeListener.CHANGES + "=ADDED",
52+
ResourceChangeListener.CHANGES + "=CHANGED",
53+
ResourceChangeListener.CHANGES + "=REMOVED",
54+
JobConsumer.PROPERTY_TOPICS + "=" + ScriptScheduler.JOB_TOPIC
5555
})
5656
@Designate(ocd = ScriptScheduler.Config.class)
5757
public class ScriptScheduler implements ResourceChangeListener, EventListener, JobConsumer {
@@ -77,25 +77,39 @@ public static JobType of(String value) {
7777
}
7878
}
7979

80-
@ObjectClassDefinition(name = "AEM Content Manager - Script Scheduler", description = "Schedules automatic scripts on instance up and script changes")
80+
@ObjectClassDefinition(
81+
name = "AEM Content Manager - Script Scheduler",
82+
description = "Schedules automatic scripts on instance up and script changes")
8183
public @interface Config {
8284

8385
@AttributeDefinition(name = "Boot Delay", description = "Time in milliseconds to wait before booting scripts")
8486
long bootDelay() default 1000 * 10; // 10 seconds
8587

86-
@AttributeDefinition(name = "User Impersonation ID", description = "Controls who accesses the repository when scripts are automatically executed. If blank, the service user 'acm-content-service' is used.")
88+
@AttributeDefinition(
89+
name = "User Impersonation ID",
90+
description =
91+
"Controls who accesses the repository when scripts are automatically executed. If blank, the service user 'acm-content-service' is used.")
8792
String userImpersonationId();
8893

89-
@AttributeDefinition(name = "Health Check Retry Interval", description = "Interval in milliseconds to retry health check if instance is not healthy")
94+
@AttributeDefinition(
95+
name = "Health Check Retry Interval",
96+
description = "Interval in milliseconds to retry health check if instance is not healthy")
9097
long healthCheckRetryInterval() default 1000 * 10; // 10 seconds
9198

92-
@AttributeDefinition(name = "Health Check Retry Count On Deployment", description = "Maximum number of retries when checking instance health on deployment")
99+
@AttributeDefinition(
100+
name = "Health Check Retry Count On Deployment",
101+
description = "Maximum number of retries when checking instance health on deployment")
93102
long healthCheckRetryCountDeployment() default 90; // * 10 seconds = 15 minutes
94103

95-
@AttributeDefinition(name = "Health Check Retry Count On Boot", description = "Maximum number of retries when checking instance health on boot script execution")
104+
@AttributeDefinition(
105+
name = "Health Check Retry Count On Boot",
106+
description = "Maximum number of retries when checking instance health on boot script execution")
96107
long healthCheckRetryCountBoot() default 60; // * 10 seconds = 10 minutes
97108

98-
@AttributeDefinition(name = "Health Check Retry Count On Cron Schedule", description = "Maximum number of retries when checking instance health on cron schedule script execution")
109+
@AttributeDefinition(
110+
name = "Health Check Retry Count On Cron Schedule",
111+
description =
112+
"Maximum number of retries when checking instance health on cron schedule script execution")
99113
long healthCheckRetryCountCron() default 3; // * 10 seconds = 30 seconds
100114
}
101115

@@ -218,8 +232,8 @@ public JobResult process(Job job) {
218232
}
219233

220234
private ScheduleResult determineSchedule(Script script, ResourceResolver resourceResolver) {
221-
try (ExecutionContext context = executor.createContext(ExecutionId.generate(), ExecutionMode.PARSE, script,
222-
resourceResolver)) {
235+
try (ExecutionContext context =
236+
executor.createContext(ExecutionId.generate(), ExecutionMode.PARSE, script, resourceResolver)) {
223237
return executor.schedule(context);
224238
}
225239
}
@@ -228,9 +242,7 @@ private ScheduleResult determineSchedule(Script script, ResourceResolver resourc
228242
private void deployJob() {
229243
LOG.info("Instance deployment - job started");
230244
if (awaitInstanceHealthy(
231-
"Instance deployment",
232-
config.healthCheckRetryCountDeployment(),
233-
config.healthCheckRetryInterval())) {
245+
"Instance deployment", config.healthCheckRetryCountDeployment(), config.healthCheckRetryInterval())) {
234246
bootWhenInstanceUp();
235247
}
236248
LOG.info("Instance deployment - job finished");
@@ -368,8 +380,8 @@ private void cronJob(String scriptPath) {
368380
}
369381

370382
private boolean checkScript(Script script, ResourceResolver resourceResolver) {
371-
try (ExecutionContext context = executor.createContext(ExecutionId.generate(), ExecutionMode.PARSE, script,
372-
resourceResolver)) {
383+
try (ExecutionContext context =
384+
executor.createContext(ExecutionId.generate(), ExecutionMode.PARSE, script, resourceResolver)) {
373385
if (executor.isLocked(context)) {
374386
LOG.info("Script '{}' already locked!", script.getPath());
375387
return false;
@@ -405,8 +417,8 @@ private boolean checkScript(Script script, ResourceResolver resourceResolver) {
405417
}
406418

407419
private void queueScript(Script script) {
408-
String userId = StringUtils.defaultIfBlank(config.userImpersonationId(),
409-
ResolverUtils.Subservice.CONTENT.userId);
420+
String userId =
421+
StringUtils.defaultIfBlank(config.userImpersonationId(), ResolverUtils.Subservice.CONTENT.userId);
410422
executionQueue.submit(script, new ExecutionContextOptions(ExecutionMode.RUN, userId));
411423
}
412424

0 commit comments

Comments
 (0)