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

feat: update backend configs regularly [WPB-14727] #18466

Merged
merged 2 commits into from
Dec 9, 2024
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"@wireapp/avs": "10.0.4",
"@wireapp/avs-debugger": "0.0.7",
"@wireapp/commons": "5.4.0",
"@wireapp/core": "46.12.0",
"@wireapp/core": "46.13.0",
"@wireapp/react-ui-kit": "9.28.0",
"@wireapp/store-engine-dexie": "2.1.15",
"@wireapp/telemetry": "0.1.4",
Expand Down
4 changes: 2 additions & 2 deletions src/script/auth/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import {actionRoot} from './module/action';
import {Root} from './page/Root';

import {Config} from '../Config';
import {updateApiVersion} from '../lifecycle/updateRemoteConfigs';
import {setAppLocale} from '../localization/Localizer';
import {APIClient} from '../service/APIClientSingleton';
import {Core} from '../service/CoreSingleton';
Expand Down Expand Up @@ -77,8 +78,7 @@ const render = (Component: FC): void => {
const config = Config.getConfig();

async function runApp() {
const [min, max] = config.SUPPORTED_API_RANGE;
const {domain} = await core.useAPIVersion(min, max, config.ENABLE_DEV_BACKEND_API);
const {domain} = await updateApiVersion();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't we need to schedule updateApiVersion job for auth app?

await initializeDataDog(config, {domain: domain});

render(Root);
Expand Down
60 changes: 60 additions & 0 deletions src/script/lifecycle/updateRemoteConfigs.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
* Wire
* Copyright (C) 2024 Wire Swiss GmbH
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see http://www.gnu.org/licenses/.
*
*/

import {TaskParams} from '@wireapp/core/lib/util/RecurringTaskScheduler';
import {container} from 'tsyringe';

import {getLogger} from 'Util/Logger';
import {TIME_IN_MILLIS} from 'Util/TimeUtil';

import {Config} from '../Config';
import {Core} from '../service/CoreSingleton';

let core: Core | undefined = undefined;
export const updateRemoteConfigLogger = getLogger('updateRemoteConfigs');

export const scheduleRecurringTask = async (params: TaskParams) => {
if (!core) {
core = container.resolve(Core);
}
return core.recurringTaskScheduler.registerTask(params);
};

export const updateApiVersion = async () => {
if (!core) {
core = container.resolve(Core);
}
const {
SUPPORTED_API_RANGE: [min, max],
ENABLE_DEV_BACKEND_API,
} = Config.getConfig();

updateRemoteConfigLogger.info('Updating api-version and info');
return core.useAPIVersion(min, max, ENABLE_DEV_BACKEND_API);
};

export const scheduleApiVersionUpdate = async () => {
// Schedule the task to run every day and add it to the window focus event
await scheduleRecurringTask({
every: TIME_IN_MILLIS.DAY,
task: updateApiVersion,
key: 'try-api-version-backend-sync',
addTaskOnWindowFocusEvent: true,
});
};
5 changes: 3 additions & 2 deletions src/script/main/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ import {externalUrl} from '../externalRoute';
import {IntegrationRepository} from '../integration/IntegrationRepository';
import {IntegrationService} from '../integration/IntegrationService';
import {startNewVersionPolling} from '../lifecycle/newVersionHandler';
import {scheduleApiVersionUpdate, updateApiVersion} from '../lifecycle/updateRemoteConfigs';
import {MediaRepository} from '../media/MediaRepository';
import {initMLSGroupConversations, initialiseSelfAndTeamConversations} from '../mls';
import {joinConversationsAfterMigrationFinalisation} from '../mls/MLSMigration/migrationFinaliser';
Expand Down Expand Up @@ -343,8 +344,8 @@ export class App {
async initApp(clientType: ClientType, onProgress: (progress: number, message?: string) => void) {
// add body information
const startTime = Date.now();
const [apiVersionMin, apiVersionMax] = this.config.SUPPORTED_API_RANGE;
await this.core.useAPIVersion(apiVersionMin, apiVersionMax, this.config.ENABLE_DEV_BACKEND_API);
await updateApiVersion();
await scheduleApiVersionUpdate();

const osCssClass = Runtime.isMacOS() ? 'os-mac' : 'os-pc';
const platformCssClass = Runtime.isDesktopApp() ? 'platform-electron' : 'platform-web';
Expand Down
15 changes: 11 additions & 4 deletions src/script/team/TeamRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ import {EventSource} from '../event/EventSource';
import {NOTIFICATION_HANDLING_STATE} from '../event/NotificationHandlingState';
import {IntegrationMapper} from '../integration/IntegrationMapper';
import {ServiceEntity} from '../integration/ServiceEntity';
import {scheduleRecurringTask, updateRemoteConfigLogger} from '../lifecycle/updateRemoteConfigs';
import {MLSMigrationStatus, getMLSMigrationStatus} from '../mls/MLSMigration/migrationStatus';
import {APIClient} from '../service/APIClientSingleton';
import {ROLE, ROLE as TEAM_ROLE, roleFromTeamPermissions} from '../user/UserPermission';
Expand Down Expand Up @@ -144,7 +145,7 @@ export class TeamRepository extends TypedEventEmitter<Events> {
});

const members = await this.loadInitialTeamMembers(teamId);
this.scheduleTeamRefresh();
await this.scheduleTeamRefresh();
return {team, features: newFeatureList, members};
}

Expand All @@ -162,18 +163,24 @@ export class TeamRepository extends TypedEventEmitter<Events> {
};
}

private readonly scheduleTeamRefresh = (): void => {
private readonly scheduleTeamRefresh = async (): Promise<void> => {
const updateTeam = async () => {
try {
updateRemoteConfigLogger.info('Updating team-settings');
await this.getTeam();
await this.updateFeatureConfig();
} catch (error) {
this.logger.error(error);
}
};

// We want to poll the latest team data every time the app is focused and every day
window.addEventListener('focus', updateTeam);
window.setInterval(updateTeam, TIME_IN_MILLIS.DAY);
await scheduleRecurringTask({
every: TIME_IN_MILLIS.DAY,
task: updateTeam,
key: 'team-refresh',
addTaskOnWindowFocusEvent: true,
});
};

private async getInitialTeamMembers(teamId: string): Promise<TeamMemberEntity[]> {
Expand Down
35 changes: 23 additions & 12 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5948,14 +5948,14 @@ __metadata:
languageName: node
linkType: hard

"@wireapp/api-client@npm:^27.13.1":
version: 27.13.1
resolution: "@wireapp/api-client@npm:27.13.1"
"@wireapp/api-client@npm:^27.13.2":
version: 27.13.2
resolution: "@wireapp/api-client@npm:27.13.2"
dependencies:
"@wireapp/commons": "npm:^5.4.0"
"@wireapp/priority-queue": "npm:^2.1.11"
"@wireapp/protocol-messaging": "npm:1.51.0"
axios: "npm:1.7.7"
axios: "npm:1.7.9"
axios-retry: "npm:4.5.0"
http-status-codes: "npm:2.3.0"
logdown: "npm:3.3.1"
Expand All @@ -5965,7 +5965,7 @@ __metadata:
tough-cookie: "npm:4.1.4"
ws: "npm:8.18.0"
zod: "npm:3.23.8"
checksum: 10/8e297f4da3ac3d4a052d5670b0ddcd6302c9a246ef61760c61b3ecf0e1e78b0d01107fa32a10ad70e8203e7e3a6cab0d2373cc52ece4bfd154f8840b2e9db84b
checksum: 10/1fbe961c5648fd349de4f59df29eb52e80d7999c7114066cfdfbf14a7c42e4ebfa6276218f4694aa4a141e7e6221e1b2bd9f65de48cfcd2c3207e330e00edc9d
languageName: node
linkType: hard

Expand Down Expand Up @@ -6030,19 +6030,19 @@ __metadata:
languageName: node
linkType: hard

"@wireapp/core@npm:46.12.0":
version: 46.12.0
resolution: "@wireapp/core@npm:46.12.0"
"@wireapp/core@npm:46.13.0":
version: 46.13.0
resolution: "@wireapp/core@npm:46.13.0"
dependencies:
"@wireapp/api-client": "npm:^27.13.1"
"@wireapp/api-client": "npm:^27.13.2"
"@wireapp/commons": "npm:^5.4.0"
"@wireapp/core-crypto": "npm:2.0.0"
"@wireapp/cryptobox": "npm:12.8.0"
"@wireapp/priority-queue": "npm:^2.1.11"
"@wireapp/promise-queue": "npm:^2.3.10"
"@wireapp/protocol-messaging": "npm:1.51.0"
"@wireapp/store-engine": "npm:5.1.11"
axios: "npm:1.7.7"
axios: "npm:1.7.9"
bazinga64: "npm:^6.3.11"
deepmerge-ts: "npm:6.0.0"
hash.js: "npm:1.1.7"
Expand All @@ -6052,7 +6052,7 @@ __metadata:
long: "npm:^5.2.0"
uuid: "npm:9.0.1"
zod: "npm:3.23.8"
checksum: 10/3553572c04ade544185d65865f7f03c6ab5ff35b9bfc198da9217bdfb3fc93ed7942b792968fe6fb10c635c506cf84cd89d64d9da068dbd473ac01b034057229
checksum: 10/30b90cdc3fdc0ba8e015bac7182244c410528ba66ed0a48c7aa647e8354e2b4fa6aa0c9e30af18923aa02551b6c10562632604c6d59537e49dc1e113d4858cb6
languageName: node
linkType: hard

Expand Down Expand Up @@ -6892,6 +6892,17 @@ __metadata:
languageName: node
linkType: hard

"axios@npm:1.7.9":
version: 1.7.9
resolution: "axios@npm:1.7.9"
dependencies:
follow-redirects: "npm:^1.15.6"
form-data: "npm:^4.0.0"
proxy-from-env: "npm:^1.1.0"
checksum: 10/b7a5f660ea53ba9c2a745bf5ad77ad8bf4f1338e13ccc3f9f09f810267d6c638c03dac88b55dae8dc98b79c57d2d6835be651d58d2af97c174f43d289a9fd007
languageName: node
linkType: hard

"axobject-query@npm:^3.1.1":
version: 3.2.1
resolution: "axobject-query@npm:3.2.1"
Expand Down Expand Up @@ -18764,7 +18775,7 @@ __metadata:
"@wireapp/avs-debugger": "npm:0.0.7"
"@wireapp/commons": "npm:5.4.0"
"@wireapp/copy-config": "npm:2.2.10"
"@wireapp/core": "npm:46.12.0"
"@wireapp/core": "npm:46.13.0"
"@wireapp/eslint-config": "npm:3.0.7"
"@wireapp/prettier-config": "npm:0.6.4"
"@wireapp/react-ui-kit": "npm:9.28.0"
Expand Down
Loading