Skip to content

Commit 5541155

Browse files
Merge pull request #209 from wttech/instance-deployment-waiting
Instance deployment waiter
2 parents 7dd4f92 + 7996198 commit 5541155

File tree

2 files changed

+29
-3
lines changed

2 files changed

+29
-3
lines changed

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

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
import java.util.Map;
2525
import java.util.Optional;
2626
import java.util.concurrent.ConcurrentHashMap;
27+
import java.util.concurrent.ExecutorService;
28+
import java.util.concurrent.Executors;
2729
import org.apache.commons.lang3.StringUtils;
2830
import org.apache.sling.api.resource.LoginException;
2931
import org.apache.sling.api.resource.ResourceResolver;
@@ -59,6 +61,8 @@ public class ScriptScheduler implements ResourceChangeListener, EventListener, J
5961

6062
public static final String JOB_TOPIC = "dev/vml/es/acm/ScriptScheduler";
6163

64+
public static final String DEPLOY_THREAD_NAME = "ScriptScheduler-Deploy";
65+
6266
public static final String JOB_PROP_TYPE = "type";
6367

6468
public static final String JOB_PROP_SCRIPT_PATH = "scriptPath";
@@ -95,10 +99,15 @@ public static JobType of(String value) {
9599
description = "Interval in milliseconds to retry health check if instance is not healthy")
96100
long healthCheckRetryInterval() default 1000 * 10; // 10 seconds
97101

102+
@AttributeDefinition(
103+
name = "Health Check Retry Count On Deployment",
104+
description = "Maximum number of retries when checking instance health on deployment")
105+
long healthCheckRetryCountDeployment() default 90; // * 10 seconds = 15 minutes
106+
98107
@AttributeDefinition(
99108
name = "Health Check Retry Count On Boot",
100109
description = "Maximum number of retries when checking instance health on boot script execution")
101-
long healthCheckRetryCountBoot() default 90; // * 10 seconds = 15 minutes
110+
long healthCheckRetryCountBoot() default 60; // * 10 seconds = 10 minutes
102111

103112
@AttributeDefinition(
104113
name = "Health Check Retry Count On Cron Schedule",
@@ -131,12 +140,15 @@ public static JobType of(String value) {
131140

132141
private Config config;
133142

143+
private ExecutorService deployJobExecutor;
144+
134145
@Activate
135146
protected void activate(Config config) {
136147
this.config = config;
137148

138149
if (checkInstanceReady()) {
139-
bootWhenInstanceUp();
150+
deployJobExecutor = Executors.newSingleThreadExecutor(r -> new Thread(r, DEPLOY_THREAD_NAME));
151+
deployJobExecutor.execute(this::deployJob);
140152
}
141153
}
142154

@@ -147,6 +159,10 @@ protected void modify(Config config) {
147159

148160
@Deactivate
149161
protected void deactivate() {
162+
if (deployJobExecutor != null) {
163+
deployJobExecutor.shutdownNow();
164+
deployJobExecutor = null;
165+
}
150166
unscheduleBoot();
151167
unscheduleScripts();
152168
bootedScripts.clear();
@@ -232,6 +248,16 @@ private ScheduleResult determineSchedule(Script script, ResourceResolver resourc
232248
}
233249
}
234250

251+
// Sling scheduler does not work during deployment on AEMaaCS, so we need to postpone boot job
252+
private void deployJob() {
253+
LOG.info("Instance deployment - job started");
254+
if (awaitInstanceHealthy(
255+
"Instance deployment", config.healthCheckRetryCountDeployment(), config.healthCheckRetryInterval())) {
256+
bootWhenInstanceUp();
257+
}
258+
LOG.info("Instance deployment - job finished");
259+
}
260+
235261
private void bootJob() {
236262
LOG.info("Automatic scripts booting - job started");
237263
unscheduleScripts();

test/project/setup.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ add_vendor_package() {
5353
<groupId>${groupId}</groupId>
5454
<artifactId>${artifactId}</artifactId>
5555
<type>${type}</type>
56-
<target>/apps/${PROJECT_NAME}-vendor-packages/container/install</target>
56+
<target>/apps/${PROJECT_NAME}-vendor-packages/application/install</target>
5757
</embedded>"
5858
local all_pom="all/pom.xml"
5959

0 commit comments

Comments
 (0)