Regression: Improve apps bridges for HA setup (#15080)

pull/15104/head
Douglas Gubert 7 years ago committed by GitHub
parent 8dbdb9d707
commit 96d6ff96c9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 6
      app/apps/client/admin/appManage.js
  2. 2
      app/apps/server/communication/rest.js
  3. 25
      app/apps/server/communication/websockets.js
  4. 12
      app/apps/server/orchestrator.js
  5. 11
      app/apps/server/storage/storage.js
  6. 2
      package.json

@ -334,7 +334,7 @@ Template.appManage.events({
event.preventDefault();
event.stopPropagation();
const { id, state } = instance;
const { appId, state } = instance;
if (state.get('isSaving')) {
return;
@ -345,14 +345,14 @@ Template.appManage.events({
const settings = state.get('settings');
try {
const toSave = Object.entries(settings)
const toSave = Object.values(settings)
.filter(({ hasChanged }) => hasChanged);
if (!toSave.length) {
return;
}
const updated = await Apps.setAppSettings(id, toSave);
const updated = await Apps.setAppSettings(appId, toSave);
updated.forEach(({ id, value }) => {
settings[id].value = value;
settings[id].oldValue = value;

@ -73,7 +73,7 @@ export class AppsRestApi {
let result;
try {
result = HTTP.get(`${ baseUrl }/v1/apps?version=${ Info.marketplaceApiVersion }`, {
result = HTTP.get(`${ baseUrl }/v1/apps`, {
headers,
});
} catch (e) {

@ -1,5 +1,5 @@
import { Meteor } from 'meteor/meteor';
import { AppStatus, AppStatusUtils } from '@rocket.chat/apps-engine/definition/AppStatus';
import { AppStatusUtils } from '@rocket.chat/apps-engine/definition/AppStatus';
export const AppEvents = Object.freeze({
APP_ADDED: 'app/added',
@ -20,11 +20,12 @@ export class AppServerListener {
this.clientStreamer = clientStreamer;
this.received = received;
this.engineStreamer.on(AppEvents.APP_ADDED, this.onAppAdded.bind(this));
this.engineStreamer.on(AppEvents.APP_STATUS_CHANGE, this.onAppStatusUpdated.bind(this));
this.engineStreamer.on(AppEvents.APP_SETTING_UPDATED, this.onAppSettingUpdated.bind(this));
this.engineStreamer.on(AppEvents.APP_REMOVED, this.onAppRemoved.bind(this));
this.engineStreamer.on(AppEvents.APP_UPDATED, this.onAppUpdated.bind(this));
this.engineStreamer.on(AppEvents.APP_ADDED, this.onAppAdded.bind(this));
this.engineStreamer.on(AppEvents.APP_SETTING_UPDATED, this.onAppSettingUpdated.bind(this));
this.engineStreamer.on(AppEvents.COMMAND_ADDED, this.onCommandAdded.bind(this));
this.engineStreamer.on(AppEvents.COMMAND_DISABLED, this.onCommandDisabled.bind(this));
this.engineStreamer.on(AppEvents.COMMAND_UPDATED, this.onCommandUpdated.bind(this));
@ -36,21 +37,27 @@ export class AppServerListener {
this.clientStreamer.emit(AppEvents.APP_ADDED, appId);
}
async onAppStatusUpdated({ appId, status }) {
const app = this.orch.getManager().getOneById(appId);
if (app.getStatus() === status) {
return;
}
this.received.set(`${ AppEvents.APP_STATUS_CHANGE }_${ appId }`, { appId, status, when: new Date() });
if (AppStatusUtils.isEnabled(status)) {
await this.orch.getManager().enable(appId);
await this.orch.getManager().enable(appId).catch(console.error);
this.clientStreamer.emit(AppEvents.APP_STATUS_CHANGE, { appId, status });
} else if (AppStatusUtils.isDisabled(status)) {
await this.orch.getManager().disable(appId, AppStatus.MANUALLY_DISABLED === status);
await this.orch.getManager().disable(appId, status, true).catch(console.error);
this.clientStreamer.emit(AppEvents.APP_STATUS_CHANGE, { appId, status });
}
}
async onAppSettingUpdated({ appId, setting }) {
this.received.set(`${ AppEvents.APP_SETTING_UPDATED }_${ appId }_${ setting.id }`, { appId, setting, when: new Date() });
await this.orch.getManager().getSettingsManager().updateAppSetting(appId, setting);
this.clientStreamer.emit(AppEvents.APP_SETTING_UPDATED, { appId });
}
@ -65,6 +72,12 @@ export class AppServerListener {
}
async onAppRemoved(appId) {
const app = this.orch.getManager().getOneById(appId);
if (!app) {
return;
}
await this.orch.getManager().remove(appId);
this.clientStreamer.emit(AppEvents.APP_REMOVED, appId);
}

@ -99,11 +99,11 @@ class AppServerOrchestrator {
return this._marketplaceUrl;
}
load() {
async load() {
// Don't try to load it again if it has
// already been loaded
if (this.isLoaded()) {
return Promise.resolve();
return;
}
return this._manager.load()
@ -111,11 +111,11 @@ class AppServerOrchestrator {
.catch((err) => console.warn('Failed to load the Apps Framework and Apps!', err));
}
unload() {
async unload() {
// Don't try to unload it if it's already been
// unlaoded or wasn't unloaded to start with
if (!this.isLoaded()) {
return Promise.resolve();
return;
}
return this._manager.unload()
@ -123,9 +123,9 @@ class AppServerOrchestrator {
.catch((err) => console.warn('Failed to unload the Apps Framework!', err));
}
updateAppsMarketplaceInfo(apps = []) {
async updateAppsMarketplaceInfo(apps = []) {
if (!this.isLoaded()) {
return Promise.resolve();
return;
}
return this._manager.updateAppsMarketplaceInfo(apps)

@ -44,11 +44,7 @@ export class AppRealStorage extends AppStorage {
return reject(e);
}
if (doc) {
resolve(doc);
} else {
reject(new Error(`No App found by the id: ${ id }`));
}
resolve(doc);
});
}
@ -74,12 +70,11 @@ export class AppRealStorage extends AppStorage {
return new Promise((resolve, reject) => {
try {
this.db.update({ id: item.id }, item);
resolve(item.id);
} catch (e) {
return reject(e);
}
this.retrieveOne(item.id).then((updated) => resolve(updated)).catch((err) => reject(err));
});
}).then(this.retrieveOne.bind(this));
}
remove(id) {

@ -133,7 +133,7 @@
"@google-cloud/language": "^2.0.0",
"@google-cloud/storage": "^2.3.1",
"@google-cloud/vision": "^0.23.0",
"@rocket.chat/apps-engine": "^1.5.1",
"@rocket.chat/apps-engine": "^1.5.2",
"@slack/client": "^4.8.0",
"adm-zip": "^0.4.13",
"apollo-server-express": "^1.3.6",

Loading…
Cancel
Save