Skip to content

Commit

Permalink
metrics: Rewrite PCPConfigDialog.handleInstall() with async
Browse files Browse the repository at this point in the history
This simplifies the code a bit, and will help with the following change.

Also factorize the `.exists` service list check, as we are going to add
a third one.
  • Loading branch information
martinpitt committed May 29, 2024
1 parent 59c92fc commit d5b41af
Showing 1 changed file with 11 additions and 13 deletions.
24 changes: 11 additions & 13 deletions pkg/metrics/metrics.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -1375,27 +1375,25 @@ const PCPConfigDialog = ({

useInit(() => packagekit.detect().then(setPackagekitExists));

const handleInstall = () => {
const handleInstall = async () => {
// when enabling services, install missing packages on demand
const missing = [];
if (dialogLoggerValue && !s_pmlogger.exists)
missing.push("cockpit-pcp");
if (dialogProxyValue && !(s_redis.exists || s_redis_server.exists))
const redisExists = () => s_redis.exists || s_redis_server.exists;
if (dialogProxyValue && !redisExists())
missing.push("redis");
if (missing.length > 0) {
debug("PCPConfig: missing packages", JSON.stringify(missing), ", offering install");
Dialogs.close();
return install_dialog(missing)
.then(() => {
debug("PCPConfig: package installation successful");
if (missing.indexOf("cockpit-pcp") >= 0)
setNeedsLogout(true);
return wait_cond(() => (s_pmlogger.exists &&
(!dialogProxyValue || (s_pmproxy.exists && (s_redis.exists || s_redis_server.exists)))),
[s_pmlogger, s_pmproxy, s_redis, s_redis_server]);
});
} else
return Promise.resolve();
await install_dialog(missing);
debug("PCPConfig: package installation successful");
if (missing.indexOf("cockpit-pcp") >= 0)
setNeedsLogout(true);
await wait_cond(() => (s_pmlogger.exists &&
(!dialogProxyValue || (s_pmproxy.exists && redisExists()))),
[s_pmlogger, s_pmproxy, s_redis, s_redis_server]);
}
};

const handleSave = () => {
Expand Down

0 comments on commit d5b41af

Please sign in to comment.