diff --git a/src/api/general-services/pipeline-manage/constants.js b/src/api/general-services/pipeline-manage/constants.js index 696b02c1a..d8bd6fa11 100644 --- a/src/api/general-services/pipeline-manage/constants.js +++ b/src/api/general-services/pipeline-manage/constants.js @@ -13,7 +13,6 @@ const SUCCEEDED = 'SUCCEEDED'; // Custom defined statuses defined in the API const NOT_CREATED = 'NOT_CREATED'; - // Additional custom statuses module.exports = { diff --git a/src/api/route-services/experiment.js b/src/api/route-services/experiment.js index 73344d1c9..407142860 100644 --- a/src/api/route-services/experiment.js +++ b/src/api/route-services/experiment.js @@ -218,6 +218,17 @@ class ExperimentService { } } + async updateLouvainCellSets(experimentId, cellSetsData) { + const cellSetsObject = await this.getCellSets(experimentId); + + const { cellSets: cellSetsList } = cellSetsObject; + + const newCellSetsList = _.filter(cellSetsList, (rootNode) => rootNode.key !== 'louvain'); + newCellSetsList.push(cellSetsData); + + await this.updateCellSets(experimentId, newCellSetsList); + } + async updateCellSets(experimentId, cellSetData) { const cellSetsObject = JSON.stringify({ cellSets: cellSetData }); diff --git a/src/api/route-services/work-response.js b/src/api/route-services/work-response.js index 3607ef9b0..bd66244be 100644 --- a/src/api/route-services/work-response.js +++ b/src/api/route-services/work-response.js @@ -4,6 +4,10 @@ const validateRequest = require('../../utils/schema-validator'); const logger = require('../../utils/logging'); const { cacheSetResponse } = require('../../utils/cache-request'); const { handlePagination } = require('../../utils/handlePagination'); +const ExperimentService = require('./experiment'); + +const NEW = 'NEW'; +const DATA_UPDATE = 'data_update'; class WorkResponseService { constructor(io, workResponse) { @@ -15,6 +19,28 @@ class WorkResponseService { })(); } + async notifyDataUpdate(responseForClient) { + const { experimentId } = responseForClient.request; + + // this should send the request so the UI can make it again if needed + // instead of sending the data to everyone + const response = { + response: responseForClient, + status: NEW, + type: DATA_UPDATE, + }; + + // for now we only want to notify about cell sets updates + if (responseForClient.request.body.name === 'ClusterCells') { + const cellSets = JSON.parse(responseForClient.results[0].body); + await (new ExperimentService()).updateLouvainCellSets(experimentId, cellSets); + } + + + logger.log('Sending to all clients subscribed to experiment', experimentId); + this.io.sockets.emit(`ExperimentUpdates-${experimentId}`, response); + } + // eslint-disable-next-line class-methods-use-this async processS3PathType(workResponse) { const s3Promises = []; @@ -102,11 +128,14 @@ class WorkResponseService { throw e; } + await this.notifyDataUpdate(responseForClient); + if (socketId === 'no-socket') { logger.log('Socket is not provided, no response sent out.'); return; } + if (Date.parse(timeout) > Date.now()) { this.io.to(socketId).emit(`WorkResponse-${uuid}`, responseForClient); logger.log('Work response sent out.');