From abd11d0172edb7ca5a49b3b5d609f003ad8fe481 Mon Sep 17 00:00:00 2001 From: Krystian Panek Date: Tue, 21 Oct 2025 07:35:29 +0200 Subject: [PATCH 1/2] Skip by extension --- .../vml/es/acm/core/code/ExecutionContext.java | 10 +++++----- .../dev/vml/es/acm/core/code/ExecutionId.java | 2 ++ .../java/dev/vml/es/acm/core/code/Executor.java | 12 +++++++++--- .../vml/es/acm/core/instance/HealthChecker.java | 3 +-- .../extension/example/ACME-300_extension.groovy | 17 ++++++----------- 5 files changed, 23 insertions(+), 21 deletions(-) diff --git a/core/src/main/java/dev/vml/es/acm/core/code/ExecutionContext.java b/core/src/main/java/dev/vml/es/acm/core/code/ExecutionContext.java index fa6ec1fe..97a2c33d 100644 --- a/core/src/main/java/dev/vml/es/acm/core/code/ExecutionContext.java +++ b/core/src/main/java/dev/vml/es/acm/core/code/ExecutionContext.java @@ -36,7 +36,7 @@ public static String varPath(String executionId) { private boolean debug = false; - private boolean locking = true; + private boolean skipped = false; private final Inputs inputs; @@ -143,12 +143,12 @@ public void setDebug(boolean debug) { this.debug = debug; } - public boolean isLocking() { - return locking; + public boolean isSkipped() { + return skipped; } - public void setLocking(boolean locking) { - this.locking = locking; + public void setSkipped(boolean skipped) { + this.skipped = skipped; } public Inputs getInputs() { diff --git a/core/src/main/java/dev/vml/es/acm/core/code/ExecutionId.java b/core/src/main/java/dev/vml/es/acm/core/code/ExecutionId.java index 7d89f7f1..9600481b 100644 --- a/core/src/main/java/dev/vml/es/acm/core/code/ExecutionId.java +++ b/core/src/main/java/dev/vml/es/acm/core/code/ExecutionId.java @@ -6,6 +6,8 @@ public final class ExecutionId { + public static final String HEALTH_CHECK = "health-check"; + private ExecutionId() { // intentionally empty } diff --git a/core/src/main/java/dev/vml/es/acm/core/code/Executor.java b/core/src/main/java/dev/vml/es/acm/core/code/Executor.java index 5ee248a9..e818aedb 100644 --- a/core/src/main/java/dev/vml/es/acm/core/code/Executor.java +++ b/core/src/main/java/dev/vml/es/acm/core/code/Executor.java @@ -183,6 +183,11 @@ public Execution execute(ExecutionContext context) throws AcmException { private ContextualExecution executeInternal(ExecutionContext context) { ContextualExecution.Builder execution = new ContextualExecution.Builder(context).start(); + boolean healthChecking = ExecutionId.HEALTH_CHECK.equals(context.getId()); + if ((!healthChecking && context.isSkipped())) { + return execution.end(ExecutionStatus.SKIPPED); + } + try { statuses.put(context.getId(), ExecutionStatus.PARSING); @@ -204,13 +209,14 @@ private ContextualExecution executeInternal(ExecutionContext context) { return execution.end(ExecutionStatus.SUCCEEDED); } + boolean locking = !healthChecking; String lockName = executableLockName(context); - if (context.isLocking() && queryLocker(resolverFactory, l -> l.isLocked(lockName))) { + if (locking && queryLocker(resolverFactory, l -> l.isLocked(lockName))) { return execution.end(ExecutionStatus.SKIPPED); } try { - if (context.isLocking()) { + if (locking) { useLocker(resolverFactory, l -> l.lock(lockName)); } statuses.put(context.getId(), ExecutionStatus.RUNNING); @@ -222,7 +228,7 @@ private ContextualExecution executeInternal(ExecutionContext context) { contentScript.run(); return execution.end(ExecutionStatus.SUCCEEDED); } finally { - if (context.isLocking()) { + if (locking) { useLocker(resolverFactory, l -> l.unlock(lockName)); } } diff --git a/core/src/main/java/dev/vml/es/acm/core/instance/HealthChecker.java b/core/src/main/java/dev/vml/es/acm/core/instance/HealthChecker.java index 140c0003..3446df94 100644 --- a/core/src/main/java/dev/vml/es/acm/core/instance/HealthChecker.java +++ b/core/src/main/java/dev/vml/es/acm/core/instance/HealthChecker.java @@ -243,7 +243,7 @@ private void checkComponents(List issues) { private void checkCodeExecutor(List issues, ResourceResolver resourceResolver) { try (ExecutionContext context = executor.createContext( - ExecutionId.generate(), + ExecutionId.HEALTH_CHECK, resourceResolver.getUserID(), ExecutionMode.RUN, Code.consoleMinimal(), @@ -251,7 +251,6 @@ private void checkCodeExecutor(List issues, ResourceResolver resour resourceResolver, new CodeOutputMemory())) { context.setHistory(false); - context.setLocking(false); Execution execution = executor.execute(context); if (execution.getStatus() != ExecutionStatus.SUCCEEDED) { diff --git a/ui.content.example/src/main/content/jcr_root/conf/acm/settings/script/extension/example/ACME-300_extension.groovy b/ui.content.example/src/main/content/jcr_root/conf/acm/settings/script/extension/example/ACME-300_extension.groovy index 268bd441..69efe3cb 100644 --- a/ui.content.example/src/main/content/jcr_root/conf/acm/settings/script/extension/example/ACME-300_extension.groovy +++ b/ui.content.example/src/main/content/jcr_root/conf/acm/settings/script/extension/example/ACME-300_extension.groovy @@ -1,19 +1,14 @@ import dev.vml.es.acm.core.code.ExecutionContext import dev.vml.es.acm.core.code.Execution +import java.util.Calendar void prepareRun(ExecutionContext context) { - context.variable("acme", new AcmeFacade()) -} - -void completeRun(Execution execution) { - if (execution.status.name() == 'FAILED') { - log.error "Something nasty happened with '${execution.executable.id}'!" - // TODO send notification using built-in 'notifier' for Slack and MS Teams or use custom HTTP client / WebAPI + def minute = Calendar.getInstance().get(Calendar.MINUTE) + if (minute % 2 == 0) { + context.skipped = true } } -class AcmeFacade { - def now() { - return new Date() - } +void completeRun(Execution execution) { + log.info "I am not skipped on even minutes!" } \ No newline at end of file From 533fa834787d64a52ef253d044356bad8dd63cc6 Mon Sep 17 00:00:00 2001 From: Krystian Panek Date: Tue, 21 Oct 2025 07:38:30 +0200 Subject: [PATCH 2/2] Revert --- .../extension/example/ACME-300_extension.groovy | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/ui.content.example/src/main/content/jcr_root/conf/acm/settings/script/extension/example/ACME-300_extension.groovy b/ui.content.example/src/main/content/jcr_root/conf/acm/settings/script/extension/example/ACME-300_extension.groovy index 69efe3cb..268bd441 100644 --- a/ui.content.example/src/main/content/jcr_root/conf/acm/settings/script/extension/example/ACME-300_extension.groovy +++ b/ui.content.example/src/main/content/jcr_root/conf/acm/settings/script/extension/example/ACME-300_extension.groovy @@ -1,14 +1,19 @@ import dev.vml.es.acm.core.code.ExecutionContext import dev.vml.es.acm.core.code.Execution -import java.util.Calendar void prepareRun(ExecutionContext context) { - def minute = Calendar.getInstance().get(Calendar.MINUTE) - if (minute % 2 == 0) { - context.skipped = true - } + context.variable("acme", new AcmeFacade()) } void completeRun(Execution execution) { - log.info "I am not skipped on even minutes!" + if (execution.status.name() == 'FAILED') { + log.error "Something nasty happened with '${execution.executable.id}'!" + // TODO send notification using built-in 'notifier' for Slack and MS Teams or use custom HTTP client / WebAPI + } +} + +class AcmeFacade { + def now() { + return new Date() + } } \ No newline at end of file