Skip to content

Commit 385b4a3

Browse files
committed
🐛 Fix Docker integration actions timeouts
1 parent 5ccdf73 commit 385b4a3

File tree

3 files changed

+39
-50
lines changed

3 files changed

+39
-50
lines changed

src/components/modules/docker/ContainerActionBar.tsx

+27-42
Original file line numberDiff line numberDiff line change
@@ -9,35 +9,36 @@ import {
99
IconRefresh,
1010
IconRotateClockwise,
1111
IconTrash,
12-
IconX,
1312
} from '@tabler/icons';
1413
import axios from 'axios';
1514
import Dockerode from 'dockerode';
1615
import { tryMatchService } from '../../../tools/addToHomarr';
17-
import { useConfig } from '../../../tools/state';
1816
import { AddAppShelfItemForm } from '../../AppShelf/AddAppShelfItem';
1917

20-
function sendDockerCommand(action: string, containerId: string, containerName: string) {
18+
function sendDockerCommand(
19+
action: string,
20+
containerId: string,
21+
containerName: string,
22+
reload: () => void
23+
) {
2124
showNotification({
2225
id: containerId,
2326
loading: true,
24-
title: `${action}ing container ${containerName.substring(1)}`,
27+
title: `${action}ing container ${containerName}`,
2528
message: undefined,
2629
autoClose: false,
2730
disallowClose: true,
2831
});
2932
axios
3033
.get(`/api/docker/container/${containerId}?action=${action}`)
3134
.then((res) => {
32-
if (res.data.success === true) {
33-
updateNotification({
34-
id: containerId,
35-
title: `Container ${containerName} ${action}ed`,
36-
message: `Your container was successfully ${action}ed`,
37-
icon: <IconCheck />,
38-
autoClose: 2000,
39-
});
40-
}
35+
updateNotification({
36+
id: containerId,
37+
title: `Container ${containerName} ${action}ed`,
38+
message: `Your container was successfully ${action}ed`,
39+
icon: <IconCheck />,
40+
autoClose: 2000,
41+
});
4142
})
4243
.catch((err) => {
4344
updateNotification({
@@ -47,6 +48,9 @@ function sendDockerCommand(action: string, containerId: string, containerName: s
4748
message: err.response.data.reason,
4849
autoClose: 2000,
4950
});
51+
})
52+
.finally(() => {
53+
reload();
5054
});
5155
}
5256

@@ -56,7 +60,6 @@ export interface ContainerActionBarProps {
5660
}
5761

5862
export default function ContainerActionBar({ selected, reload }: ContainerActionBarProps) {
59-
const { config, setConfig } = useConfig();
6063
const [opened, setOpened] = useBooleanToggle(false);
6164
return (
6265
<Group>
@@ -78,19 +81,9 @@ export default function ContainerActionBar({ selected, reload }: ContainerAction
7881
onClick={() =>
7982
Promise.all(
8083
selected.map((container) =>
81-
sendDockerCommand('restart', container.Id, container.Names[0].substring(1))
84+
sendDockerCommand('restart', container.Id, container.Names[0].substring(1), reload)
8285
)
8386
)
84-
.catch((err) => {
85-
showNotification({
86-
color: 'red',
87-
title: 'There was an error with your container.',
88-
message: err.message,
89-
icon: <IconX />,
90-
autoClose: 2000,
91-
});
92-
})
93-
.then(() => reload())
9487
}
9588
variant="light"
9689
color="orange"
@@ -103,9 +96,9 @@ export default function ContainerActionBar({ selected, reload }: ContainerAction
10396
onClick={() =>
10497
Promise.all(
10598
selected.map((container) =>
106-
sendDockerCommand('stop', container.Id, container.Names[0].substring(1))
99+
sendDockerCommand('stop', container.Id, container.Names[0].substring(1), reload)
107100
)
108-
).then(() => reload())
101+
)
109102
}
110103
variant="light"
111104
color="red"
@@ -118,9 +111,9 @@ export default function ContainerActionBar({ selected, reload }: ContainerAction
118111
onClick={() =>
119112
Promise.all(
120113
selected.map((container) =>
121-
sendDockerCommand('start', container.Id, container.Names[0].substring(1))
114+
sendDockerCommand('start', container.Id, container.Names[0].substring(1), reload)
122115
)
123-
).then(() => reload())
116+
)
124117
}
125118
variant="light"
126119
color="green"
@@ -140,7 +133,7 @@ export default function ContainerActionBar({ selected, reload }: ContainerAction
140133
if (selected.length !== 1) {
141134
showNotification({
142135
autoClose: 5000,
143-
title: <Title order={4}>Please only add one service at a time!</Title>,
136+
title: <Title order={5}>Please only add one service at a time!</Title>,
144137
color: 'red',
145138
message: undefined,
146139
});
@@ -158,18 +151,10 @@ export default function ContainerActionBar({ selected, reload }: ContainerAction
158151
radius="md"
159152
onClick={() =>
160153
Promise.all(
161-
selected.map((container) => {
162-
if (container.State === 'running') {
163-
return showNotification({
164-
id: container.Id,
165-
title: `Failed to delete ${container.Names[0].substring(1)}`,
166-
message: "You can't delete a running container",
167-
autoClose: 1000,
168-
});
169-
}
170-
return sendDockerCommand('remove', container.Id, container.Names[0].substring(1));
171-
})
172-
).then(() => reload())
154+
selected.map((container) =>
155+
sendDockerCommand('remove', container.Id, container.Names[0].substring(1), reload)
156+
)
157+
)
173158
}
174159
>
175160
Remove

src/components/modules/downloads/DownloadsModule.tsx

+5-3
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ export default function DownloadComponent() {
5353
useEffect(() => {
5454
setIsLoading(true);
5555
if (downloadServices.length === 0) return;
56-
const interval = setSafeInterval(() => {
56+
const interval = setInterval(() => {
5757
// Send one request with each download service inside
5858
axios
5959
.post('/api/modules/downloads')
@@ -66,14 +66,16 @@ export default function DownloadComponent() {
6666
// eslint-disable-next-line no-console
6767
console.error('Error while fetching torrents', error.response.data);
6868
setIsLoading(false);
69-
clearInterval(interval);
7069
showNotification({
7170
title: 'Error fetching torrents',
72-
autoClose: false,
71+
autoClose: 1000,
72+
disallowClose: true,
73+
id: 'fail-torrent-downloads-module',
7374
color: 'red',
7475
message:
7576
'Please check your config for any potential errors, check the console for more info',
7677
});
78+
clearInterval(interval);
7779
});
7880
}, 5000);
7981
}, []);

src/components/modules/downloads/TotalDownloadsModule.tsx

+7-5
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ export default function TotalDownloadsComponent() {
4343
const totalDownloadSpeed = torrents.reduce((acc, torrent) => acc + torrent.downloadSpeed, 0);
4444
const totalUploadSpeed = torrents.reduce((acc, torrent) => acc + torrent.uploadSpeed, 0);
4545
useEffect(() => {
46-
if (downloadServices.length === 0) return;
4746
const interval = setSafeInterval(() => {
47+
// Send one request with each download service inside
4848
axios
4949
.post('/api/modules/downloads')
5050
.then((response) => {
@@ -54,14 +54,16 @@ export default function TotalDownloadsComponent() {
5454
setTorrents([]);
5555
// eslint-disable-next-line no-console
5656
console.error('Error while fetching torrents', error.response.data);
57-
clearInterval(interval);
5857
showNotification({
59-
title: 'Error fetching torrents',
60-
autoClose: false,
58+
title: 'Torrent speed module failed to fetch torrents',
59+
autoClose: 1000,
60+
disallowClose: true,
61+
id: 'fail-torrent-speed-module',
6162
color: 'red',
6263
message:
63-
'Please check your config for any potential errors, check the console for more info',
64+
'Error fetching torrents, please check your config for any potential errors, check the console for more info',
6465
});
66+
clearInterval(interval);
6567
});
6668
}, 1000);
6769
}, [config.services]);

0 commit comments

Comments
 (0)