Skip to content

Commit

Permalink
reorg imports
Browse files Browse the repository at this point in the history
  • Loading branch information
ggazzo committed Mar 27, 2024
1 parent 2f7bc67 commit 870bb27
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 55 deletions.
81 changes: 42 additions & 39 deletions apps/meteor/ee/app/license/server/startup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,57 +96,60 @@ export const startLicense = async () => {
}
};

// When settings are loaded, apply the current license if there is one.
settings.onReady(async () => {
if (!(await applyLicense(settings.get<string>('Enterprise_License') ?? '', false))) {
// License from the envvar is always treated as new, because it would have been saved on the setting if it was already in use.
if (process.env.ROCKETCHAT_LICENSE && !License.hasValidLicense()) {
await applyLicense(process.env.ROCKETCHAT_LICENSE, true);
License.setLicenseLimitCounter('activeUsers', () => Users.getActiveLocalUserCount());
License.setLicenseLimitCounter('guestUsers', () => Users.getActiveLocalGuestCount());
License.setLicenseLimitCounter('roomsPerGuest', async (context) => (context?.userId ? Subscriptions.countByUserId(context.userId) : 0));
License.setLicenseLimitCounter('privateApps', () => getAppCount('private'));
License.setLicenseLimitCounter('marketplaceApps', () => getAppCount('marketplace'));
License.setLicenseLimitCounter('monthlyActiveContacts', () => LivechatVisitors.countVisitorsOnPeriod(moment.utc().format('YYYY-MM')));

return new Promise<void>((resolve) => {
// When settings are loaded, apply the current license if there is one.
settings.onReady(async () => {
if (!(await applyLicense(settings.get<string>('Enterprise_License') ?? '', false))) {
// License from the envvar is always treated as new, because it would have been saved on the setting if it was already in use.
if (process.env.ROCKETCHAT_LICENSE && !License.hasValidLicense()) {
await applyLicense(process.env.ROCKETCHAT_LICENSE, true);
}
}
}

// After the current license is already loaded, watch the setting value to react to new licenses being applied.
settings.change<string>('Enterprise_License', (license) => applyLicenseOrRemove(license, true));
// After the current license is already loaded, watch the setting value to react to new licenses being applied.
settings.change<string>('Enterprise_License', (license) => applyLicenseOrRemove(license, true));

callbacks.add('workspaceLicenseRemoved', () => License.remove());
callbacks.add('workspaceLicenseRemoved', () => License.remove());

callbacks.add('workspaceLicenseChanged', (updatedLicense) => applyLicense(updatedLicense, true));
callbacks.add('workspaceLicenseChanged', (updatedLicense) => applyLicense(updatedLicense, true));

License.onInstall(async () => void api.broadcast('license.actions', {} as Record<Partial<LicenseLimitKind>, boolean>));
License.onInstall(async () => void api.broadcast('license.actions', {} as Record<Partial<LicenseLimitKind>, boolean>));

License.onInvalidate(async () => void api.broadcast('license.actions', {} as Record<Partial<LicenseLimitKind>, boolean>));
License.onInvalidate(async () => void api.broadcast('license.actions', {} as Record<Partial<LicenseLimitKind>, boolean>));

License.onBehaviorTriggered('prevent_action', (context) => syncByTriggerDebounced(`prevent_action_${context.limit}`));
License.onBehaviorTriggered('prevent_action', (context) => syncByTriggerDebounced(`prevent_action_${context.limit}`));

License.onBehaviorTriggered('start_fair_policy', async (context) => syncByTriggerDebounced(`start_fair_policy_${context.limit}`));
License.onBehaviorTriggered('start_fair_policy', async (context) => syncByTriggerDebounced(`start_fair_policy_${context.limit}`));

License.onBehaviorTriggered('disable_modules', async (context) => syncByTriggerDebounced(`disable_modules_${context.limit}`));
License.onBehaviorTriggered('disable_modules', async (context) => syncByTriggerDebounced(`disable_modules_${context.limit}`));

License.onChange(() => api.broadcast('license.sync'));
License.onChange(() => api.broadcast('license.sync'));

License.onBehaviorToggled('prevent_action', (context) => {
if (!context.limit) {
return;
}
void api.broadcast('license.actions', {
[context.limit]: true,
} as Record<Partial<LicenseLimitKind>, boolean>);
});
License.onBehaviorToggled('prevent_action', (context) => {
if (!context.limit) {
return;
}
void api.broadcast('license.actions', {
[context.limit]: true,
} as Record<Partial<LicenseLimitKind>, boolean>);
});

License.onBehaviorToggled('allow_action', (context) => {
if (!context.limit) {
return;
}
void api.broadcast('license.actions', {
[context.limit]: false,
} as Record<Partial<LicenseLimitKind>, boolean>);
License.onBehaviorToggled('allow_action', (context) => {
if (!context.limit) {
return;
}
void api.broadcast('license.actions', {
[context.limit]: false,
} as Record<Partial<LicenseLimitKind>, boolean>);
});
resolve();
});
});

License.setLicenseLimitCounter('activeUsers', () => Users.getActiveLocalUserCount());
License.setLicenseLimitCounter('guestUsers', () => Users.getActiveLocalGuestCount());
License.setLicenseLimitCounter('roomsPerGuest', async (context) => (context?.userId ? Subscriptions.countByUserId(context.userId) : 0));
License.setLicenseLimitCounter('privateApps', () => getAppCount('private'));
License.setLicenseLimitCounter('marketplaceApps', () => getAppCount('marketplace'));
License.setLicenseLimitCounter('monthlyActiveContacts', () => LivechatVisitors.countVisitorsOnPeriod(moment.utc().format('YYYY-MM')));
};
33 changes: 17 additions & 16 deletions apps/meteor/server/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import './models/startup';
* and the startup should be done in parallel
*/
import './settings';
import '../app/settings/server';

import { startLicense } from '../ee/app/license/server/startup';
import { registerEEBroker } from '../ee/server';
Expand All @@ -16,29 +17,29 @@ import { startup } from './startup';

import './routes';
import '../app/lib/server/startup';
import './importPackages';
import './methods';
import './publications';
import './lib/logger/startup';
import '../lib/oauthRedirectUriServer';
import './lib/pushConfig';
import './features/EmailInbox/index';

const StartupLogger = new Logger('StartupLogger');

StartupLogger.startup('Starting Rocket.Chat server...');

await import('../app/settings/server').then(() => StartupLogger.startup('Settings started'));
await registerEEBroker().then(() => StartupLogger.startup('EE Broker registered'));

await Promise.all([
import('./importPackages').then(() => StartupLogger.startup('Imported packages')),
import('./methods').then(() => StartupLogger.startup('Imported methods')),
import('./publications').then(() => StartupLogger.startup('Imported publications')),
import('./lib/logger/startup').then(() => StartupLogger.startup('Logger started')),
import('../lib/oauthRedirectUriServer').then(() => StartupLogger.startup('OAuth redirect uri server started')),
import('./lib/pushConfig').then(() => StartupLogger.startup('Push configuration started')),
import('./features/EmailInbox/index').then(() => StartupLogger.startup('EmailInbox started')),
configureLogLevel().then(() => StartupLogger.startup('Log level configured')),
registerServices().then(() => StartupLogger.startup('Services registered')),
import('../ee/server/startup/services'),
configureLoginServices().then(() => StartupLogger.startup('Login services configured')),
startup().then(() => StartupLogger.startup('Startup finished')),
]);
await (async () => {
await Promise.all([
configureLogLevel().then(() => StartupLogger.startup('Log level configured')),
registerServices().then(() => StartupLogger.startup('Services registered')),
configureLoginServices().then(() => StartupLogger.startup('Login services configured')),
startup().then(() => StartupLogger.startup('Startup finished')),
]);
})();

await startLicense().then(() => StartupLogger.startup('License started'));

await import('../ee/server/startup/services');
StartupLogger.startup('Rocket.Chat server started.');

0 comments on commit 870bb27

Please sign in to comment.