Skip to content

Commit

Permalink
send fluxapprunning before installing process, send fluxappremoved if…
Browse files Browse the repository at this point in the history
… there is any error returned
  • Loading branch information
Cabecinha84 committed Jan 5, 2024
1 parent 0e81f53 commit 1e16eee
Showing 1 changed file with 33 additions and 21 deletions.
54 changes: 33 additions & 21 deletions ZelBack/src/services/appsService.js
Original file line number Diff line number Diff line change
Expand Up @@ -3383,27 +3383,6 @@ async function registerAppLocally(appSpecs, componentSpecs, res) {
} else {
await installApplicationHard(specificationsToInstall, appName, isComponent, res, appSpecifications);
}

const broadcastedAt = new Date().getTime();
const newAppRunningMessage = {
type: 'fluxapprunning',
version: 1,
name: appSpecifications.name,
hash: appSpecifications.hash, // hash of application specifics that are running
ip: myIP,
broadcastedAt,
runningSince: broadcastedAt,
};

// store it in local database first
// eslint-disable-next-line no-await-in-loop, no-use-before-define
await storeAppRunningMessage(newAppRunningMessage);
// broadcast messages about running apps to all peers
await fluxCommunicationMessagesSender.broadcastMessageToOutgoing(newAppRunningMessage);
await serviceHelper.delay(500);
await fluxCommunicationMessagesSender.broadcastMessageToIncoming(newAppRunningMessage);
// broadcast messages about running apps to all peers

// all done message
const successStatus = messageHelper.createSuccessMessage(`Flux App ${appName} successfully installed and launched`);
log.info(successStatus);
Expand Down Expand Up @@ -8896,11 +8875,44 @@ async function trySpawningGlobalApplication() {
trySpawningGlobalApplication();
return;
}

let broadcastedAt = new Date().getTime();
const newAppRunningMessage = {
type: 'fluxapprunning',
version: 1,
name: appSpecifications.name,
hash: appSpecifications.hash, // hash of application specifics that are running
ip: myIP,
broadcastedAt,
runningSince: broadcastedAt,
};

// store it in local database first
// eslint-disable-next-line no-await-in-loop, no-use-before-define
await storeAppRunningMessage(newAppRunningMessage);
// broadcast messages about running apps to all peers
await fluxCommunicationMessagesSender.broadcastMessageToOutgoing(newAppRunningMessage);
await serviceHelper.delay(500);
await fluxCommunicationMessagesSender.broadcastMessageToIncoming(newAppRunningMessage);

// an application was selected and checked that it can run on this node. try to install and run it locally
// install the app
const registerOk = await registerAppLocally(appSpecifications); // can throw
if (!registerOk) {
log.info('Error on registerAppLocally');
broadcastedAt = new Date().getTime();
const appRemovedMessage = {
type: 'fluxappremoved',
version: 1,
appName: appSpecifications.name,
ip: myIP,
broadcastedAt,
};
log.info('Broadcasting appremoved message to the network');
// broadcast messages about app removed to all peers
await fluxCommunicationMessagesSender.broadcastMessageToOutgoing(appRemovedMessage);
await serviceHelper.delay(500);
await fluxCommunicationMessagesSender.broadcastMessageToIncoming(appRemovedMessage);
await serviceHelper.delay(adjustedDelay);
trySpawningGlobalApplication();
return;
Expand Down

0 comments on commit 1e16eee

Please sign in to comment.