Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only recreate on modified user settings #2035

Merged
merged 2 commits into from
Sep 20, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 25 additions & 10 deletions packages/stakers/src/stakerComponent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export class StakerComponent {
userSettings: UserSettings;
}): Promise<void> {
logs.info(`Persisting ${dnpName}`);
await this.setStakerPkgConfig({ dnpName, isInstalled: true, userSettings, forceRecreate: false });
await this.setStakerPkgConfig({ dnpName, isInstalled: true, userSettings });
}

protected async setNew({
Expand Down Expand Up @@ -133,27 +133,42 @@ export class StakerComponent {
private async setStakerPkgConfig({
dnpName,
isInstalled,
userSettings,
forceRecreate = true
userSettings
}: {
dnpName: string;
isInstalled: boolean;
userSettings: UserSettings;
forceRecreate?: boolean;
}): Promise<void> {
// ensure pkg installed
if (!isInstalled)
if (isInstalled) {
await this.setInstalledStakerPkgConfig({ dnpName, userSettings });
} else {
await packageInstall(this.dappnodeInstaller, {
name: dnpName,
userSettings: userSettings ? { [dnpName]: userSettings } : {}
});
else if (userSettings) {
}
}

private async setInstalledStakerPkgConfig({
dnpName,
userSettings
}: {
dnpName: string;
userSettings: UserSettings;
}): Promise<void> {
let forceRecreate = false;

if (userSettings) {
const composeEditor = new ComposeFileEditor(dnpName, false);
const userSettingsPrev: UserSettingsAllDnps = {};
userSettingsPrev[dnpName] = composeEditor.getUserSettings();
if (!isMatch(userSettingsPrev, userSettings)) {

const previousSettings: UserSettingsAllDnps = {
[dnpName]: composeEditor.getUserSettings()
};

if (!isMatch(previousSettings, userSettings)) {
composeEditor.applyUserSettings(userSettings, { dnpName });
composeEditor.write();
forceRecreate = true; // Only recreate if userSettings changed
}
}

Expand Down
Loading