Skip to content

Commit

Permalink
[Enhancement kbss-cvut#535] Add button to the maintenance-administrat…
Browse files Browse the repository at this point in the history
…ion for clearing the long-running tasks queue (background processes)
  • Loading branch information
lukaskabc committed Dec 10, 2024
1 parent 0b0f407 commit 9ace04d
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 15 deletions.
1 change: 1 addition & 0 deletions src/action/ActionType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,7 @@ enum ActionType {

DOES_USERNAME_EXISTS = "DOES_USERNAME_EXISTS",
LONG_RUNNING_TASKS_UPDATE = "LONG_RUNNING_TASKS_UPDATE",
CLEAR_LONG_RUNNING_TASKS_QUEUE = "CLEAR_LONG_RUNNING_TASKS_QUEUE",
}

export default ActionType;
23 changes: 23 additions & 0 deletions src/action/AsyncActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1234,6 +1234,29 @@ export function invalidateCaches() {
};
}

export function clearLongRunningTasksQueue() {
const action = { type: ActionType.CLEAR_LONG_RUNNING_TASKS_QUEUE };
return (dispatch: ThunkDispatch) => {
dispatch(asyncActionRequest(action));
return Ajax.delete(`${Constants.API_PREFIX}/admin/long-running-tasks`)
.then(() => dispatch(asyncActionSuccess(action)))
.then(() =>
dispatch(
publishMessage(
new Message(
{
messageId:
"administration.maintenance.clearLongRunningTasksQueue.success",
},
MessageType.SUCCESS
)
)
)
)
.catch((error) => dispatch(asyncActionFailure(action, error)));
};
}

export function loadConfiguration() {
const action = { type: ActionType.LOAD_CONFIGURATION };
return (dispatch: ThunkDispatch) => {
Expand Down
36 changes: 21 additions & 15 deletions src/component/administration/Maintenance.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import * as React from "react";
import { Button, ButtonToolbar } from "reactstrap";
import PanelWithActions from "../misc/PanelWithActions";
import { connect } from "react-redux";
import { ThunkDispatch } from "../../util/Types";
import { invalidateCaches } from "../../action/AsyncActions";
import { useI18n } from "../hook/useI18n";

interface MaintenanceProps {
invalidateCache: () => void;
}
import { useI18n } from "../hook/useI18n";
import {
clearLongRunningTasksQueue,
invalidateCaches,
} from "../../action/AsyncActions";
import { ThunkDispatch } from "../../util/Types";
import { useDispatch } from "react-redux";

export const Maintenance: React.FC<MaintenanceProps> = (props) => {
const { invalidateCache } = props;
export const Maintenance: React.FC = () => {
const dispatch: ThunkDispatch = useDispatch();
const { i18n } = useI18n();
return (
<PanelWithActions title={i18n("administration.maintenance.title")}>
Expand All @@ -20,17 +20,23 @@ export const Maintenance: React.FC<MaintenanceProps> = (props) => {
color="primary"
size="sm"
title={i18n("administration.maintenance.invalidateCaches.tooltip")}
onClick={invalidateCache}
onClick={() => dispatch(invalidateCaches())}
>
{i18n("administration.maintenance.invalidateCaches")}
</Button>
<Button
color="primary"
size="sm"
title={i18n(
"administration.maintenance.clearLongRunningTasksQueue.tooltip"
)}
onClick={() => dispatch(clearLongRunningTasksQueue())}
>
{i18n("administration.maintenance.clearLongRunningTasksQueue")}
</Button>
</ButtonToolbar>
</PanelWithActions>
);
};

export default connect(undefined, (dispatch: ThunkDispatch) => {
return {
invalidateCache: () => dispatch(invalidateCaches()),
};
})(Maintenance);
export default Maintenance;
6 changes: 6 additions & 0 deletions src/i18n/cs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,12 @@ const cs = {
"Vyprázdnit interní cache systému",
"administration.maintenance.invalidateCaches.success":
"Cache úspěšně vyprázdněna.",
"administration.maintenance.clearLongRunningTasksQueue":
"Vyprádznit frontu procesů na pozadí",
"administration.maintenance.clearLongRunningTasksQueue.tooltip":
"Vyprázdnit frontu procesů čekajících na zpracování na pozadí",
"administration.maintenance.clearLongRunningTasksQueue.success":
"Fronta procesů na pozadí úspěšně vyprázdněna.",
"administration.groups": "Uživatelské skupiny",
"administration.groups.create": "Vytvořit skupinu",
"administration.groups.create.tooltip":
Expand Down
6 changes: 6 additions & 0 deletions src/i18n/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,12 @@ const en = {
"Invalidate system's internal caches",
"administration.maintenance.invalidateCaches.success":
"Caches successfully cleared.",
"administration.maintenance.clearLongRunningTasksQueue":
"Clear background process queue",
"administration.maintenance.clearLongRunningTasksQueue.tooltip":
"Clears the queue of processes that are waiting to be executed in the background",
"administration.maintenance.clearLongRunningTasksQueue.success":
"Background process queue successfully cleared.",
"administration.groups": "User groups",
"administration.groups.create": "Create group",
"administration.groups.create.tooltip": "Allows to create a new user group",
Expand Down

0 comments on commit 9ace04d

Please sign in to comment.