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

notifying worker of job done #151

Merged
merged 4 commits into from
Jun 11, 2021
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
1 change: 0 additions & 1 deletion src/api/general-services/pipeline-manage/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ const SUCCEEDED = 'SUCCEEDED';

// Custom defined statuses defined in the API
const NOT_CREATED = 'NOT_CREATED';

// Additional custom statuses

module.exports = {
Expand Down
11 changes: 11 additions & 0 deletions src/api/route-services/experiment.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 });

Expand Down
29 changes: 29 additions & 0 deletions src/api/route-services/work-response.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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);
Copy link
Contributor

Choose a reason for hiding this comment

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

Isn't it better to instantiate ExperimentService outside this function?

Copy link
Contributor

Choose a reason for hiding this comment

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

This will be turned into functions in static classes in another ticket

}


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 = [];
Expand Down Expand Up @@ -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.');
Expand Down