24
24
import java .util .Map ;
25
25
import java .util .Optional ;
26
26
import java .util .concurrent .ConcurrentHashMap ;
27
+ import java .util .concurrent .ExecutorService ;
28
+ import java .util .concurrent .Executors ;
27
29
import org .apache .commons .lang3 .StringUtils ;
28
30
import org .apache .sling .api .resource .LoginException ;
29
31
import org .apache .sling .api .resource .ResourceResolver ;
@@ -59,6 +61,8 @@ public class ScriptScheduler implements ResourceChangeListener, EventListener, J
59
61
60
62
public static final String JOB_TOPIC = "dev/vml/es/acm/ScriptScheduler" ;
61
63
64
+ public static final String DEPLOY_THREAD_NAME = "ScriptScheduler-Deploy" ;
65
+
62
66
public static final String JOB_PROP_TYPE = "type" ;
63
67
64
68
public static final String JOB_PROP_SCRIPT_PATH = "scriptPath" ;
@@ -95,10 +99,15 @@ public static JobType of(String value) {
95
99
description = "Interval in milliseconds to retry health check if instance is not healthy" )
96
100
long healthCheckRetryInterval () default 1000 * 10 ; // 10 seconds
97
101
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
+
98
107
@ AttributeDefinition (
99
108
name = "Health Check Retry Count On Boot" ,
100
109
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
102
111
103
112
@ AttributeDefinition (
104
113
name = "Health Check Retry Count On Cron Schedule" ,
@@ -131,12 +140,15 @@ public static JobType of(String value) {
131
140
132
141
private Config config ;
133
142
143
+ private ExecutorService deployJobExecutor ;
144
+
134
145
@ Activate
135
146
protected void activate (Config config ) {
136
147
this .config = config ;
137
148
138
149
if (checkInstanceReady ()) {
139
- bootWhenInstanceUp ();
150
+ deployJobExecutor = Executors .newSingleThreadExecutor (r -> new Thread (r , DEPLOY_THREAD_NAME ));
151
+ deployJobExecutor .execute (this ::deployJob );
140
152
}
141
153
}
142
154
@@ -147,6 +159,10 @@ protected void modify(Config config) {
147
159
148
160
@ Deactivate
149
161
protected void deactivate () {
162
+ if (deployJobExecutor != null ) {
163
+ deployJobExecutor .shutdownNow ();
164
+ deployJobExecutor = null ;
165
+ }
150
166
unscheduleBoot ();
151
167
unscheduleScripts ();
152
168
bootedScripts .clear ();
@@ -232,6 +248,16 @@ private ScheduleResult determineSchedule(Script script, ResourceResolver resourc
232
248
}
233
249
}
234
250
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
+
235
261
private void bootJob () {
236
262
LOG .info ("Automatic scripts booting - job started" );
237
263
unscheduleScripts ();
0 commit comments