Skip to content

Commit

Permalink
notifying worker of job done
Browse files Browse the repository at this point in the history
  • Loading branch information
kafkasl committed Jun 10, 2021
1 parent 744f790 commit 2bdab92
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 1 deletion.
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
34 changes: 34 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,12 @@ 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 experimentService = new ExperimentService();

const NEW = 'NEW';
const DATA_UPDATE = 'data_update';

class WorkResponseService {
constructor(io, workResponse) {
Expand All @@ -15,6 +21,29 @@ class WorkResponseService {
})();
}

async notifyDataUpdate(responseForClient) {
const { experimentId } = responseForClient.request;

// this should resend the request so the UI can replay it
// instead of sending the data to everyone
const response = {
// response: responseForClient,
request: responseForClient.request,
status: NEW,
type: DATA_UPDATE,
};

console.log('RESPONSE FOR CLIENT');
console.log(responseForClient);
// const cellsets = responseForClient.results[0].body;

// await experimentService.updateCellSets(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 = [];
Expand Down Expand Up @@ -102,11 +131,16 @@ class WorkResponseService {
throw e;
}

// const { experimentId } = responseForClient.request;

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
2 changes: 2 additions & 0 deletions src/api/routes/experiment.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ module.exports = {
'experiment#updateCellSets': [
expressAuthorizationMiddleware,
(req, res, next) => {
console.log('REQUEST UPDATE FOR CELLSETS MORTY');
console.log(req);
experimentService.updateCellSets(req.params.experimentId, req.body)
.then((data) => res.json(data))
.catch(next);
Expand Down

0 comments on commit 2bdab92

Please sign in to comment.