Skip to content

Commit bf746c9

Browse files
Troubleshoot button
1 parent 6073b44 commit bf746c9

File tree

5 files changed

+86
-27
lines changed

5 files changed

+86
-27
lines changed

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

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -163,19 +163,8 @@ public void onChange(List<ResourceChange> changes) {
163163
@Override
164164
public void onEvent(Event event) {
165165
EventType eventType = EventType.of(event.getName()).orElse(null);
166-
if (eventType == null) {
167-
return;
168-
}
169-
switch (eventType) {
170-
case SCRIPT_SCHEDULER_BOOT:
171-
bootOnDemand();
172-
break;
173-
case EXECUTOR_RESET:
174-
reset();
175-
break;
176-
default:
177-
// ignore else
178-
break;
166+
if (eventType == EventType.SCRIPT_SCHEDULER_BOOT) {
167+
bootOnDemand();
179168
}
180169
}
181170

@@ -437,13 +426,4 @@ private boolean awaitInstanceHealthy(String operation, long retryMaxCount, long
437426
}
438427
return true;
439428
}
440-
441-
public void reset() {
442-
findJobs().forEach(job -> jobManager.removeJobById(job.getId()));
443-
}
444-
445-
@SuppressWarnings("unchecked")
446-
private Stream<Job> findJobs() {
447-
return jobManager.findJobs(JobManager.QueryType.ALL, JOB_TOPIC, -1, Collections.emptyMap()).stream();
448-
}
449429
}

ui.frontend/src/components/CodeExecutor.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ import { intervalToTimeout } from '../utils/spectrum.ts';
1919
import DateExplained from './DateExplained';
2020
import ExecutableIdValue from './ExecutableIdValue';
2121
import ExecutionsAbortButton from './ExecutionsAbortButton';
22-
import ExecutionsResetButton from './ExecutionsResetButton';
22+
import ExecutorResetButton from './ExecutorResetButton';
23+
import ExecutorBootButton from './ExecutorBootButton';
2324
import ExecutionStatusBadge from './ExecutionStatusBadge';
2425
import UserInfo from './UserInfo';
2526

@@ -98,7 +99,8 @@ const CodeExecutor = () => {
9899
</Item>
99100
</Menu>
100101
</MenuTrigger>
101-
<ExecutionsResetButton />
102+
<ExecutorResetButton />
103+
<ExecutorBootButton />
102104
</ButtonGroup>
103105
</Flex>
104106
<Flex flex="1" justifyContent="center" alignItems="center">
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
import { Button, ButtonGroup, Content, Dialog, DialogTrigger, Divider, Heading, Text } from '@adobe/react-spectrum';
2+
import Alert from '@spectrum-icons/workflow/Alert';
3+
import Cancel from '@spectrum-icons/workflow/Cancel';
4+
import Checkmark from '@spectrum-icons/workflow/Checkmark';
5+
import Launch from '@spectrum-icons/workflow/Launch';
6+
import React, { useState } from 'react';
7+
import { toastRequest } from '../utils/api.ts';
8+
import { EventType, QueueOutput } from '../utils/api.types.ts';
9+
10+
type ExecutionsBootButtonProps = {
11+
onBoot?: () => void;
12+
};
13+
14+
const ExecutorBootButton: React.FC<ExecutionsBootButtonProps> = ({ onBoot }) => {
15+
const [bootDialogOpen, setBootDialogOpen] = useState(false);
16+
const [isLoading, setIsLoading] = useState(false);
17+
18+
const handleConfirm = async () => {
19+
setIsLoading(true);
20+
try {
21+
await toastRequest<QueueOutput>({
22+
method: 'POST',
23+
url: `/apps/acm/api/event.json?name=${EventType.SCRIPT_SCHEDULER_BOOT}`,
24+
operation: 'Boot script scheduler',
25+
});
26+
if (onBoot) onBoot();
27+
} catch (error) {
28+
console.error('Boot script scheduler error:', error);
29+
} finally {
30+
setIsLoading(false);
31+
setBootDialogOpen(false);
32+
}
33+
};
34+
35+
const renderBootDialog = () => (
36+
<>
37+
<Heading>
38+
<Text>Confirmation</Text>
39+
</Heading>
40+
<Divider />
41+
<Content>
42+
<Text>
43+
<p>
44+
Are you sure you want to force boot the script scheduler? This may be useful if the automatic scheduler has reached a timeout.
45+
<br />
46+
</p>
47+
<p>
48+
<Alert size="XS" /> This action will <strong>affect all instances</strong>.
49+
</p>
50+
</Text>
51+
</Content>
52+
<ButtonGroup>
53+
<Button variant="secondary" onPress={() => setBootDialogOpen(false)} isDisabled={isLoading}>
54+
<Cancel />
55+
<Text>Cancel</Text>
56+
</Button>
57+
<Button variant="negative" style="fill" onPress={handleConfirm} isPending={isLoading}>
58+
<Checkmark />
59+
<Text>Confirm</Text>
60+
</Button>
61+
</ButtonGroup>
62+
</>
63+
);
64+
65+
return (
66+
<DialogTrigger isOpen={bootDialogOpen} onOpenChange={setBootDialogOpen}>
67+
<Button variant="secondary" style="fill" onPress={() => setBootDialogOpen(true)}>
68+
<Launch />
69+
<Text>Boot</Text>
70+
</Button>
71+
<Dialog>{renderBootDialog()}</Dialog>
72+
</DialogTrigger>
73+
);
74+
};
75+
76+
export default ExecutorBootButton;

ui.frontend/src/components/ExecutionsResetButton.tsx renamed to ui.frontend/src/components/ExecutorResetButton.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@ import Cancel from '@spectrum-icons/workflow/Cancel';
44
import Checkmark from '@spectrum-icons/workflow/Checkmark';
55
import GearsDelete from '@spectrum-icons/workflow/GearsDelete';
66
import React, { useState } from 'react';
7-
import { toastRequest } from '../utils/api';
7+
import { toastRequest } from '../utils/api.ts';
88
import { EventType, QueueOutput } from '../utils/api.types.ts';
99

1010
type ExecutionsResetButtonProps = {
1111
onReset?: () => void;
1212
};
1313

14-
const ExecutionsResetButton: React.FC<ExecutionsResetButtonProps> = ({ onReset }) => {
14+
const ExecutorResetButton: React.FC<ExecutionsResetButtonProps> = ({ onReset }) => {
1515
const [resetDialogOpen, setResetDialogOpen] = useState(false);
1616
const [isLoading, setIsLoading] = useState(false);
1717

@@ -73,4 +73,4 @@ const ExecutionsResetButton: React.FC<ExecutionsResetButtonProps> = ({ onReset }
7373
);
7474
};
7575

76-
export default ExecutionsResetButton;
76+
export default ExecutorResetButton;

ui.frontend/src/utils/api.types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -440,4 +440,5 @@ export type FileOutput = {
440440
export enum EventType {
441441
EXECUTOR_RESET = 'executor_reset',
442442
HISTORY_CLEAR = 'history_clear',
443+
SCRIPT_SCHEDULER_BOOT = 'script_scheduler_boot',
443444
}

0 commit comments

Comments
 (0)