Skip to content

Commit 466b3dc

Browse files
committed
tuned: Rework logic to gracefully to handle the service starting
Previously starting the service would lead to a server disconnected message, these changes allow us to instead fully wait until the service has started before showing the profile selection, meaning we no longer encounter that error
1 parent c790a0b commit 466b3dc

File tree

1 file changed

+62
-8
lines changed

1 file changed

+62
-8
lines changed

pkg/systemd/overview-cards/tuned-dialog.jsx

Lines changed: 62 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ export const TunedPerformanceProfile = () => {
4141
const [btnText, setBtnText] = useState();
4242
const [state, setState] = useState();
4343
const [status, setStatus] = useState();
44+
const [openDialog, setOpenDialog] = useState(false);
4445

4546
const tunedService = useObject(() => service.proxy("tuned.service"),
4647
null,
@@ -105,11 +106,32 @@ export const TunedPerformanceProfile = () => {
105106
updateButton();
106107
}, [updateButton]);
107108

108-
const showDialog = () => {
109-
Dialogs.show(<TunedDialog updateButton={updateButton}
110-
poll={poll}
111-
tunedDbus={tuned} tunedService={tunedService} />);
112-
};
109+
const startTuned = useCallback(() => {
110+
tunedService.start()
111+
.then(() => setOpenDialog(true));
112+
}, [tunedService, setOpenDialog]);
113+
114+
const showDialog = useCallback(() => {
115+
if (tunedService.state !== "running") {
116+
if (!openDialog) {
117+
Dialogs.show(<StartTunedDialog startTuned={startTuned} />);
118+
}
119+
} else {
120+
setOpenDialog(false);
121+
if (Dialogs.isActive()) {
122+
Dialogs.close();
123+
}
124+
Dialogs.show(<TunedDialog updateButton={updateButton}
125+
poll={poll}
126+
tunedDbus={tuned} tunedService={tunedService} />);
127+
}
128+
}, [updateButton, poll, startTuned, tuned, tunedService, openDialog, setOpenDialog, Dialogs]);
129+
130+
useEffect(() => {
131+
if (openDialog) {
132+
showDialog();
133+
}
134+
}, [openDialog, showDialog]);
113135

114136
return (
115137
<Tooltip id="tuned-status-tooltip" content={status}>
@@ -124,6 +146,39 @@ export const TunedPerformanceProfile = () => {
124146
);
125147
};
126148

149+
const StartTunedDialog = ({
150+
startTuned,
151+
}) => {
152+
const [loading, setLoading] = useState(false);
153+
const Dialogs = useDialogs();
154+
155+
const startService = () => {
156+
setLoading(true);
157+
startTuned();
158+
};
159+
160+
return (
161+
<Modal position="top" variant="medium"
162+
className="ct-m-stretch-body"
163+
isOpen
164+
onClose={Dialogs.close}
165+
title={_("Tuned is not running")}
166+
footer={
167+
<>
168+
<Button variant='primary' onClick={startService}>
169+
{_("Start service")}
170+
</Button>
171+
<Button variant='link' onClick={Dialogs.close}>
172+
{_("Cancel")}
173+
</Button>
174+
</>
175+
}
176+
>
177+
{loading && <EmptyStatePanel loading />}
178+
</Modal>
179+
);
180+
};
181+
127182
const TunedDialog = ({
128183
updateButton,
129184
poll,
@@ -244,7 +299,7 @@ const TunedDialog = ({
244299
const tunedProfiles = () => {
245300
return tunedDbus.call('/Tuned', 'com.redhat.tuned.control', 'profiles2', [])
246301
.then((result) => result[0])
247-
.catch(ex => {
302+
.catch(() => {
248303
return tunedDbus.call('/Tuned', 'com.redhat.tuned.control', 'profiles', [])
249304
.then((result) => result[0]);
250305
});
@@ -266,8 +321,7 @@ const TunedDialog = ({
266321
.catch(setError);
267322
};
268323

269-
tunedService.start()
270-
.then(updateButton)
324+
updateButton()
271325
.then(withTuned)
272326
.catch(setError)
273327
.finally(() => setLoading(false));

0 commit comments

Comments
 (0)