Skip to content

Commit

Permalink
tuned: Rework logic to gracefully to handle the service starting
Browse files Browse the repository at this point in the history
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
  • Loading branch information
SludgeGirl committed Jul 12, 2024
1 parent c790a0b commit de9ab3e
Showing 1 changed file with 66 additions and 11 deletions.
77 changes: 66 additions & 11 deletions pkg/systemd/overview-cards/tuned-dialog.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export const TunedPerformanceProfile = () => {
const [btnText, setBtnText] = useState();
const [state, setState] = useState();
const [status, setStatus] = useState();
const [openDialog, setOpenDialog] = useState(false);

const tunedService = useObject(() => service.proxy("tuned.service"),
null,
Expand Down Expand Up @@ -105,11 +106,32 @@ export const TunedPerformanceProfile = () => {
updateButton();
}, [updateButton]);

const showDialog = () => {
Dialogs.show(<TunedDialog updateButton={updateButton}
poll={poll}
tunedDbus={tuned} tunedService={tunedService} />);
};
const startTuned = useCallback(() => {
tunedService.start()
.then(() => setOpenDialog(true));
}, [tunedService, setOpenDialog]);

const showDialog = useCallback(() => {
if (tunedService.state !== "running") {
if (!openDialog) {
Dialogs.show(<StartTunedDialog startTuned={startTuned} />);
}
} else {
setOpenDialog(false);
if (Dialogs.isActive()) {
Dialogs.close();
}
Dialogs.show(<TunedDialog updateButton={updateButton}
poll={poll}
tunedDbus={tuned} tunedService={tunedService} />);
}
}, [updateButton, poll, tuned, tunedService, openDialog, setOpenDialog, Dialogs]);

useEffect(() => {
if (openDialog) {
showDialog();
}
}, [openDialog, showDialog]);

return (
<Tooltip id="tuned-status-tooltip" content={status}>
Expand All @@ -124,6 +146,40 @@ export const TunedPerformanceProfile = () => {
);
};

const StartTunedDialog = ({
startTuned,
}) => {
const [loading, setLoading] = useState(false);
const Dialogs = useDialogs();

const startService = () => {
setLoading(true);
startTuned();
};

return (
<Modal position="top" variant="medium"
className="ct-m-stretch-body"
isOpen
onClose={Dialogs.close}
title={_("Tuned is not running")}
footer={
<>
<Button variant='primary' onClick={startService}>
{_("Start service")}
</Button>
<Button variant='link' onClick={Dialogs.close}>
{_("Cancel")}
</Button>
</>
}
>
{loading && <EmptyStatePanel loading />}
</Modal>
)

}

const TunedDialog = ({
updateButton,
poll,
Expand Down Expand Up @@ -244,7 +300,7 @@ const TunedDialog = ({
const tunedProfiles = () => {
return tunedDbus.call('/Tuned', 'com.redhat.tuned.control', 'profiles2', [])
.then((result) => result[0])
.catch(ex => {
.catch(() => {
return tunedDbus.call('/Tuned', 'com.redhat.tuned.control', 'profiles', [])
.then((result) => result[0]);
});
Expand All @@ -266,11 +322,10 @@ const TunedDialog = ({
.catch(setError);
};

tunedService.start()
.then(updateButton)
.then(withTuned)
.catch(setError)
.finally(() => setLoading(false));
updateButton()
.then(withTuned)
.catch(setError)
.finally(() => setLoading(false));
}, [updateButton, poll, tunedService, tunedDbus]);

const help = (
Expand Down

0 comments on commit de9ab3e

Please sign in to comment.