Skip to content

Commit dc818ec

Browse files
Merge pull request #210 from wttech/script-scheduler-fix
Script scheduler cluster fix
2 parents 5541155 + 18dd33a commit dc818ec

File tree

6 files changed

+52
-67
lines changed

6 files changed

+52
-67
lines changed

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

Lines changed: 4 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@
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;
2927
import org.apache.commons.lang3.StringUtils;
3028
import org.apache.sling.api.resource.LoginException;
3129
import org.apache.sling.api.resource.ResourceResolver;
@@ -61,8 +59,6 @@ public class ScriptScheduler implements ResourceChangeListener, EventListener, J
6159

6260
public static final String JOB_TOPIC = "dev/vml/es/acm/ScriptScheduler";
6361

64-
public static final String DEPLOY_THREAD_NAME = "ScriptScheduler-Deploy";
65-
6662
public static final String JOB_PROP_TYPE = "type";
6763

6864
public static final String JOB_PROP_SCRIPT_PATH = "scriptPath";
@@ -140,15 +136,12 @@ public static JobType of(String value) {
140136

141137
private Config config;
142138

143-
private ExecutorService deployJobExecutor;
144-
145139
@Activate
146140
protected void activate(Config config) {
147141
this.config = config;
148142

149143
if (checkInstanceReady()) {
150-
deployJobExecutor = Executors.newSingleThreadExecutor(r -> new Thread(r, DEPLOY_THREAD_NAME));
151-
deployJobExecutor.execute(this::deployJob);
144+
bootWhenInstanceUp();
152145
}
153146
}
154147

@@ -159,12 +152,10 @@ protected void modify(Config config) {
159152

160153
@Deactivate
161154
protected void deactivate() {
162-
if (deployJobExecutor != null) {
163-
deployJobExecutor.shutdownNow();
164-
deployJobExecutor = null;
155+
if (!instanceInfo.isCluster()) {
156+
unscheduleBoot();
157+
unscheduleScripts();
165158
}
166-
unscheduleBoot();
167-
unscheduleScripts();
168159
bootedScripts.clear();
169160
instanceReady = null;
170161
}
@@ -248,16 +239,6 @@ private ScheduleResult determineSchedule(Script script, ResourceResolver resourc
248239
}
249240
}
250241

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-
261242
private void bootJob() {
262243
LOG.info("Automatic scripts booting - job started");
263244
unscheduleScripts();

ui.frontend/src/components/CodeExecutor.tsx

Lines changed: 37 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,13 @@ const CodeExecutor = () => {
7878
<Flex flex="1" alignItems="center">
7979
<ButtonGroup>
8080
<ExecutionsAbortButton selectedKeys={selectedIds(selectedKeys)} />
81+
</ButtonGroup>
82+
</Flex>
83+
<Flex flex="1" justifyContent="center" alignItems="center">
84+
<StatusLight variant={executions.length === 0 ? 'positive' : 'notice'}>{executions.length === 0 ? <>Idle</> : <>Busy &mdash; {executions.length} execution(s)</>}</StatusLight>
85+
</Flex>
86+
<Flex flex="1" justifyContent="end" alignItems="center">
87+
<ButtonGroup>
8188
<MenuTrigger>
8289
<Button variant="negative" isDisabled={appState.instanceSettings.type === InstanceType.CLOUD_CONTAINER}>
8390
<Settings />
@@ -99,41 +106,36 @@ const CodeExecutor = () => {
99106
</Menu>
100107
</MenuTrigger>
101108
<ExecutorResetButton />
102-
</ButtonGroup>
103-
</Flex>
104-
<Flex flex="1" justifyContent="center" alignItems="center">
105-
<StatusLight variant={executions.length === 0 ? 'positive' : 'notice'}>{executions.length === 0 ? <>Idle</> : <>Busy &mdash; {executions.length} execution(s)</>}</StatusLight>
106-
</Flex>
107-
<Flex flex="1" justifyContent="end" alignItems="center">
108-
<DialogTrigger>
109-
<Button variant="secondary" style="fill">
110-
<Help />
111-
<Text>Help</Text>
112-
</Button>
113-
{(close) => (
114-
<Dialog>
115-
<Heading>Code Executor</Heading>
116-
<Divider />
117-
<Content>
118-
<p>
119-
<Replay size="XS" /> Here you can preview queued and active executions. You can also abort them if they were run in the background by other users or in separate browser tabs/windows.
120-
</p>
121-
<p>
122-
<Checkmark size="XS" /> It allows you to freely hit the &apos;Execute&apos; button in the console, close the browser, and get back to the script output anytime. Once an execution ends, it is saved in history.
123-
</p>
124-
<p>
125-
<Cancel size="XS" /> Remember that aborting executions may leave data in an inconsistent state.
126-
</p>
127-
</Content>
128-
<ButtonGroup>
129-
<Button variant="secondary" onPress={close}>
130-
<Close size="XS" />
131-
<Text>Close</Text>
132-
</Button>
133-
</ButtonGroup>
134-
</Dialog>
135-
)}
136-
</DialogTrigger>
109+
<DialogTrigger>
110+
<Button variant="secondary" style="fill">
111+
<Help />
112+
<Text>Help</Text>
113+
</Button>
114+
{(close) => (
115+
<Dialog>
116+
<Heading>Code Executor</Heading>
117+
<Divider />
118+
<Content>
119+
<p>
120+
<Replay size="XS" /> Here you can preview queued and active executions. You can also abort them if they were run in the background by other users or in separate browser tabs/windows.
121+
</p>
122+
<p>
123+
<Checkmark size="XS" /> It allows you to freely hit the &apos;Execute&apos; button in the console, close the browser, and get back to the script output anytime. Once an execution ends, it is saved in history.
124+
</p>
125+
<p>
126+
<Cancel size="XS" /> Remember that aborting executions may leave data in an inconsistent state.
127+
</p>
128+
</Content>
129+
<ButtonGroup>
130+
<Button variant="secondary" onPress={close}>
131+
<Close size="XS" />
132+
<Text>Close</Text>
133+
</Button>
134+
</ButtonGroup>
135+
</Dialog>
136+
)}
137+
</DialogTrigger>
138+
</ButtonGroup>
137139
</Flex>
138140
</Flex>
139141
</View>

ui.frontend/src/components/ExecutorBootButton.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ const ExecutorBootButton: React.FC<ExecutionsBootButtonProps> = ({ onBoot }) =>
6464

6565
return (
6666
<DialogTrigger isOpen={bootDialogOpen} onOpenChange={setBootDialogOpen}>
67-
<Button variant="secondary" style="fill" onPress={() => setBootDialogOpen(true)}>
67+
<Button variant="secondary" style="outline" onPress={() => setBootDialogOpen(true)}>
6868
<Launch />
6969
<Text>Boot</Text>
7070
</Button>

ui.frontend/src/components/ExecutorResetButton.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ const ExecutorResetButton: React.FC<ExecutionsResetButtonProps> = ({ onReset })
6464

6565
return (
6666
<DialogTrigger isOpen={resetDialogOpen} onOpenChange={setResetDialogOpen}>
67-
<Button variant="secondary" style="fill" onPress={() => setResetDialogOpen(true)}>
67+
<Button variant="secondary" style="outline" onPress={() => setResetDialogOpen(true)}>
6868
<GearsDelete />
6969
<Text>Reset</Text>
7070
</Button>

ui.frontend/src/components/ScriptAutomaticList.tsx

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -66,18 +66,20 @@ const ScriptAutomaticList: React.FC = () => {
6666
<ScriptsDeleteButton selectedKeys={selectedIds(selectedKeys)} onDelete={handleLoadScripts} />
6767
<ScriptsSyncButton selectedKeys={selectedIds(selectedKeys)} onSync={handleLoadScripts} />
6868
</Toggle>
69-
<Button variant="negative" isDisabled={appState.instanceSettings.type === InstanceType.CLOUD_CONTAINER} onPress={() => window.open(instanceOsgiServiceConfigUrl(InstanceOsgiServicePid.SCRIPT_SCHEDULER), '_blank')}>
70-
<Settings />
71-
<Text>Configure</Text>
72-
</Button>
73-
<ExecutorBootButton />
7469
</ButtonGroup>
7570
</Flex>
7671
<Flex flex="1" justifyContent="center" alignItems="center">
7772
<ScriptExecutorStatusLight />
7873
</Flex>
7974
<Flex flex="1" justifyContent="end" alignItems="center">
80-
<ScriptsAutomaticHelpButton />
75+
<ButtonGroup>
76+
<Button variant="negative" isDisabled={appState.instanceSettings.type === InstanceType.CLOUD_CONTAINER} onPress={() => window.open(instanceOsgiServiceConfigUrl(InstanceOsgiServicePid.SCRIPT_SCHEDULER), '_blank')}>
77+
<Settings />
78+
<Text>Configure</Text>
79+
</Button>
80+
<ExecutorBootButton />
81+
<ScriptsAutomaticHelpButton />
82+
</ButtonGroup>
8183
</Flex>
8284
</Flex>
8385
</View>

ui.frontend/src/components/ScriptsSyncButton.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ const ScriptsSyncButton: React.FC<ScriptSynchronizeButtonProps> = ({ selectedKey
3737
<DialogTrigger isOpen={syncDialogOpen} onOpenChange={setSyncDialogOpen}>
3838
<Button variant="primary" onPress={() => setSyncDialogOpen(true)} isDisabled={selectedKeys.length > 0}>
3939
<UploadToCloud />
40-
<Text>Sync</Text>
40+
<Text>Synchronize</Text>
4141
</Button>
4242
<Dialog>
4343
<Heading>

0 commit comments

Comments
 (0)