Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rerun all buttons #68

Merged
merged 9 commits into from
Sep 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
*.iml
*.ipr

### VSCode ###
.vscode

# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*
replay_pid*
Expand Down
2 changes: 1 addition & 1 deletion db-scheduler-ui-frontend/src/components/FilterBox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export const FilterBox: React.FC<{
<Box
display={'flex'}
mb={2}
mt={2}
mt={0}
flex={1}
justifyContent={'end'}
alignSelf={'start'}
Expand Down
123 changes: 86 additions & 37 deletions db-scheduler-ui-frontend/src/components/HeaderBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* limitations under the License.
*/
import React from 'react';
import { Box, Input, Text } from '@chakra-ui/react';
import { Box, Button, Input, Text } from '@chakra-ui/react';
import { FilterBy } from 'src/models/QueryParams';
import { FilterBox } from './FilterBox';
import { RefreshButton } from 'src/components/RefreshButton';
Expand All @@ -22,6 +22,9 @@ import { Log } from 'src/models/Log';
import { Task } from 'src/models/Task';
import { POLL_LOGS_QUERY_KEY, pollLogs } from 'src/services/pollLogs';
import { POLL_TASKS_QUERY_KEY, pollTasks } from 'src/services/pollTasks';
import { PlayIcon, RepeatIcon } from 'src/assets/icons';
import colors from 'src/styles/colors';
import { RunAllAlert } from './RunAllAlert';

interface HeaderBarProps {
inputPlaceholder: string;
Expand All @@ -46,43 +49,89 @@ export const HeaderBar: React.FC<HeaderBarProps> = ({
refetch,
title,
history,
}) => (
<Box
display={'flex'}
mb={7}
alignItems={'center'}
justifyContent={'space-between'}
w={'100%'}
>
<Box display={'flex'} alignItems={'center'} flex={1}>
<Box>
<Text ml={1} fontSize={'3xl'} fontWeight={'semibold'}>
{title}
</Text>
<Input
placeholder={inputPlaceholder}
onChange={(e) => setSearchTerm(e.currentTarget.value)}
bgColor={'white'}
w={'30vmax'}
mt={7}
ml={1}
/>
taskName,
}) => {
const [isOpen, setIsOpen] = React.useState('');

return (
<Box
display={'flex'}
mb={7}
alignItems={'center'}
justifyContent={'space-between'}
w={'100%'}
>
<Box display={'flex'} alignItems={'center'} flex={1}>
<Box>
<Box display={'flex'} alignItems={'center'}>
<Text ml={1} fontSize={'3xl'} fontWeight={'semibold'}>
{title}
</Text>
{taskName && (
<>
<Button
leftIcon={<PlayIcon />}
bgColor={colors.running['100']}
textColor={colors.running['500']}
_hover={{ backgroundColor: colors.running['200'] }}
_active={{ backgroundColor: colors.running['100'] }}
ml={5}
minW={'6em'}
onClick={() => {
setIsOpen('scheduled');
}}
>
Run all
</Button>
<Button
leftIcon={<RepeatIcon boxSize={6} />}
bgColor={colors.running['300']}
textColor={colors.primary['100']}
_hover={{ backgroundColor: colors.running['400'] }}
_active={{ backgroundColor: colors.running['300'] }}
mx={5}
minW={'10em'}
onClick={() => {
setIsOpen('failed');
}}
>
Rerun all failed
</Button>
<RunAllAlert
taskName={taskName}
isOpen={!!isOpen}
setIsopen={setIsOpen}
onlyFailed={isOpen === 'failed'}
refetch={refetch ?? (() => {})}
/>
</>
)}
</Box>
<Input
placeholder={inputPlaceholder}
onChange={(e) => setSearchTerm(e.currentTarget.value)}
bgColor={colors.primary['100']}
w={'30vmax'}
mt={7}
ml={1}
/>
</Box>
</Box>
</Box>
<Box height={'100%'}>
<FilterBox
currentFilter={currentFilter}
setCurrentFilter={setCurrentFilter}
history={history}
/>
<Box display={'flex'} float={'right'} alignItems={'center'}>
<RefreshButton
pollFunction={history ? pollLogs : pollTasks}
pollKey={history ? POLL_LOGS_QUERY_KEY : POLL_TASKS_QUERY_KEY}
refetch={refetch}
params={{ searchTerm, filter: currentFilter }}
<Box>
<FilterBox
currentFilter={currentFilter}
setCurrentFilter={setCurrentFilter}
history={history}
/>
<Box display={'flex'} float={'right'} alignItems={'center'}>
<RefreshButton
pollFunction={history ? pollLogs : pollTasks}
pollKey={history ? POLL_LOGS_QUERY_KEY : POLL_TASKS_QUERY_KEY}
refetch={refetch}
params={{ searchTerm, filter: FilterBy.All }}
/>
</Box>
</Box>
</Box>
</Box>
);
);
};
99 changes: 99 additions & 0 deletions db-scheduler-ui-frontend/src/components/RunAllAlert.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
/*
* Copyright (C) Bekk
*
* <p>Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of the License at
*
* <p>http://www.apache.org/licenses/LICENSE-2.0
*
* <p>Unless required by applicable law or agreed to in writing, software distributed under the
* License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing permissions and
* limitations under the License.
*/
import {
AlertDialog,
AlertDialogBody,
AlertDialogContent,
AlertDialogFooter,
AlertDialogHeader,
AlertDialogOverlay,
Button,
} from '@chakra-ui/react';
import React from 'react';
import runTaskGroup from 'src/services/runTaskGroup';
import colors from 'src/styles/colors';

interface TaskProps {
onlyFailed: boolean;
taskName: string;
style?: React.CSSProperties;
isOpen: boolean;
setIsopen: React.Dispatch<React.SetStateAction<string>>;
refetch: () => void;
}

export const RunAllAlert: React.FC<TaskProps> = ({
onlyFailed,
taskName,
isOpen,
setIsopen,
refetch,
}) => {
const cancelRef = React.useRef(null);
return (
<AlertDialog
isOpen={isOpen}
leastDestructiveRef={cancelRef}
onClose={() => setIsopen('')}
>
<AlertDialogOverlay>
<AlertDialogContent>
<AlertDialogHeader fontSize="lg" fontWeight="bold">
{onlyFailed ? 'Rerun All Failed' : 'Run All'}
</AlertDialogHeader>

<AlertDialogBody>
Are you sure you want to
{onlyFailed ? ' rerun all failed' : ' run all'} tasks with taskname:
{' ' + taskName}. This will include the ones outside of your current
filters and search.
</AlertDialogBody>

<AlertDialogFooter>
<Button
onClick={() => {
setIsopen('');
}}
>
Cancel
</Button>
<Button
bgColor={onlyFailed ? colors.running[300] : colors.running[100]}
_hover={{
backgroundColor: onlyFailed
? colors.running[200]
: colors.running[100],
}}
_active={{
backgroundColor: onlyFailed
? colors.running[200]
: colors.running[300],
}}
textColor={onlyFailed ? colors.primary[100] : colors.running[500]}
onClick={() => {
runTaskGroup(taskName, onlyFailed).then(() => {
refetch();
});
setIsopen('');
}}
ml={3}
>
{onlyFailed ? 'Rerun All' : 'Run All'}
</Button>
</AlertDialogFooter>
</AlertDialogContent>
</AlertDialogOverlay>
</AlertDialog>
);
};
31 changes: 31 additions & 0 deletions db-scheduler-ui-frontend/src/services/runTaskGroup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* Copyright (C) Bekk
*
* <p>Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of the License at
*
* <p>http://www.apache.org/licenses/LICENSE-2.0
*
* <p>Unless required by applicable law or agreed to in writing, software distributed under the
* License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing permissions and
* limitations under the License.
*/
const API_BASE_URL: string =
(import.meta.env.VITE_API_BASE_URL as string) ??
window.location.origin + '/db-scheduler-api';

const runTaskGroup = async (name: string, onlyFailed: boolean) => {
const response = await fetch(
`${API_BASE_URL}/tasks/rerunGroup?name=${name}&onlyFailed=${onlyFailed}`,
{
method: 'POST',
},
);

if (!response.ok) {
throw new Error(`Error executing task. Status: ${response.statusText}`);
}
};

export default runTaskGroup;
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ public void runNow(@RequestParam String id, @RequestParam String name) {
taskLogic.runTaskNow(id, name);
}

@PostMapping("/rerunGroup")
public void runAllNow(@RequestParam String name, @RequestParam boolean onlyFailed) {
taskLogic.runTaskGroupNow(name, onlyFailed);
}

@PostMapping("/delete")
public void deleteTaskNow(@RequestParam String id, @RequestParam String name) {
taskLogic.deleteTask(id, name);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,34 @@ public void runTaskNow(String taskId, String taskName) {
Optional<ScheduledExecution<Object>> scheduledExecutionOpt =
scheduler.getScheduledExecution(TaskInstanceId.of(taskName, taskId));

if (scheduledExecutionOpt.isPresent()) {
TaskInstanceId taskInstance = scheduledExecutionOpt.get().getTaskInstance();
scheduler.reschedule(taskInstance, Instant.now());
if (scheduledExecutionOpt.isPresent() && !scheduledExecutionOpt.get().isPicked()) {
scheduler.reschedule(scheduledExecutionOpt.get().getTaskInstance(), Instant.now());
} else {
throw new ResponseStatusException(
HttpStatus.NOT_FOUND,
"No ScheduledExecution found for taskName: " + taskName + ", taskId: " + taskId);
}
}

public void runTaskGroupNow(String taskName, boolean onlyFailed) {
caching
.getExecutionsFromCacheOrDB(false, scheduler)
.forEach(
(execution) -> {
if ((!onlyFailed || execution.getConsecutiveFailures() > 0)
&& taskName.equals(execution.getTaskInstance().getTaskName())) {
try {
runTaskNow(
execution.getTaskInstance().getId(),
execution.getTaskInstance().getTaskName());
} catch (ResponseStatusException e) {
System.out.println("Failed to run task: " + e.getMessage());
}
}
;
});
}

public void deleteTask(String taskId, String taskName) {
Optional<ScheduledExecution<Object>> scheduledExecutionOpt =
scheduler.getScheduledExecution(TaskInstanceId.of(taskName, taskId));
Expand Down