refactor(core): Simplify license autorenewal on leadership transition (#13503)

This commit is contained in:
Iván Ovejero 2025-02-25 17:22:15 +01:00 committed by GitHub
parent b984deac3b
commit 288cce6370
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 10 additions and 26 deletions

View file

@ -285,20 +285,4 @@ describe('License', () => {
); );
}); });
}); });
describe('reinit', () => {
it('should reinitialize license manager', async () => {
const license = new License(mockLogger(), mock(), mock(), mock(), mock());
await license.init();
const initSpy = jest.spyOn(license, 'init');
await license.reinit();
expect(initSpy).toHaveBeenCalledWith({ forceRecreate: true });
expect(LicenseManager.prototype.reset).toHaveBeenCalled();
expect(LicenseManager.prototype.initialize).toHaveBeenCalled();
});
});
}); });

View file

@ -263,11 +263,11 @@ export class Start extends BaseCommand {
orchestrationService.multiMainSetup orchestrationService.multiMainSetup
.on('leader-stepdown', async () => { .on('leader-stepdown', async () => {
await this.license.reinit(); // to disable renewal this.license.disableAutoRenewals();
await this.activeWorkflowManager.removeAllTriggerAndPollerBasedWorkflows(); await this.activeWorkflowManager.removeAllTriggerAndPollerBasedWorkflows();
}) })
.on('leader-takeover', async () => { .on('leader-takeover', async () => {
await this.license.reinit(); // to enable renewal this.license.enableAutoRenewals();
await this.activeWorkflowManager.addAllTriggerAndPollerBasedWorkflows(); await this.activeWorkflowManager.addAllTriggerAndPollerBasedWorkflows();
}); });
} }

View file

@ -381,14 +381,6 @@ export class License {
return this.getUsersLimit() === UNLIMITED_LICENSE_QUOTA; return this.getUsersLimit() === UNLIMITED_LICENSE_QUOTA;
} }
async reinit() {
if (this.manager) {
await this.manager.reset();
}
await this.init({ forceRecreate: true });
this.logger.debug('License reinitialized');
}
/** /**
* Ensures that the instance is licensed for multi-main setup if multi-main mode is enabled * Ensures that the instance is licensed for multi-main setup if multi-main mode is enabled
*/ */
@ -429,4 +421,12 @@ export class License {
Container.get(ObjectStoreService).setReadonly(true); Container.get(ObjectStoreService).setReadonly(true);
} }
} }
enableAutoRenewals() {
this.manager?.enableAutoRenewals();
}
disableAutoRenewals() {
this.manager?.disableAutoRenewals();
}
} }