-
Notifications
You must be signed in to change notification settings - Fork 0
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
On http changes for workflow progress #1
base: master
Are you sure you want to change the base?
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,13 +4,14 @@ | |
|
||
var di = require('di'); | ||
|
||
module.exports = notificationApiServiceFactory; | ||
di.annotate(notificationApiServiceFactory, new di.Provide('Http.Services.Api.Notification')); | ||
di.annotate(notificationApiServiceFactory, | ||
module.exports = NotificationApiServiceFactory; | ||
di.annotate(NotificationApiServiceFactory, new di.Provide('Http.Services.Api.Notification')); | ||
di.annotate(NotificationApiServiceFactory, | ||
new di.Inject( | ||
'Protocol.Events', | ||
'Protocol.Task', | ||
'TaskGraph.Store', | ||
'TaskGraph.TaskGraph', | ||
'Logger', | ||
'Services.Waterline', | ||
'Errors', | ||
|
@@ -19,45 +20,46 @@ di.annotate(notificationApiServiceFactory, | |
) | ||
); | ||
|
||
function notificationApiServiceFactory( | ||
function NotificationApiServiceFactory( | ||
eventsProtocol, | ||
taskProtocol, | ||
taskGraphStore, | ||
TaskGraph, | ||
Logger, | ||
waterline, | ||
Errors, | ||
Promise, | ||
_ | ||
) { | ||
var logger = Logger.initialize(notificationApiServiceFactory); | ||
var logger = Logger.initialize(NotificationApiServiceFactory); | ||
|
||
function notificationApiService() { | ||
function NotificationApiService() { | ||
} | ||
|
||
notificationApiService.prototype.postNotification = function(message) { | ||
NotificationApiService.prototype.postNotification = function(message) { | ||
var self = this; | ||
|
||
if (_.has(message, 'nodeId')) { | ||
return self.postNodeNotification(message); | ||
} else if (_.has(message, 'taskId') && _.has(message, 'progress')) { | ||
// This will be progress update notification if taskId is specified | ||
return self.postProgressEvent(message); | ||
} | ||
// Add other cases here if to support more notification types | ||
|
||
// This will be a broadcast notification if no id (like nodeId) is specified | ||
else { | ||
// This will be a broadcast notification if no id (like nodeId) is specified | ||
return self.postBroadcastNotification(message); | ||
} | ||
}; | ||
|
||
notificationApiService.prototype.postNodeNotification = function(message) { | ||
var self = this; | ||
NotificationApiService.prototype.postNodeNotification = function(message) { | ||
|
||
return Promise.try(function() { | ||
if (!message.nodeId || !_.isString(message.nodeId)) { | ||
throw new Errors.BadRequestError('Invalid node ID in query or body'); | ||
}; | ||
} | ||
}) | ||
.then(function () { | ||
return waterline.nodes.needByIdentifier(message.nodeId) | ||
return waterline.nodes.needByIdentifier(message.nodeId); | ||
}) | ||
.then(function (node) { | ||
if(!node) { | ||
|
@@ -70,14 +72,47 @@ function notificationApiServiceFactory( | |
}); | ||
}; | ||
|
||
notificationApiService.prototype.postBroadcastNotification = function(message) { | ||
var self = this; | ||
|
||
NotificationApiService.prototype.postBroadcastNotification = function(message) { | ||
return eventsProtocol.publishBroadcastNotification(message) | ||
.then(function () { | ||
return message; | ||
}); | ||
}; | ||
|
||
return new notificationApiService(); | ||
NotificationApiService.prototype.postProgressEvent = function(data) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would suggest to change function name to |
||
var progressData; | ||
return waterline.taskdependencies.find({taskId: data.taskId}) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Copy @yyscamper 's comments at on-taskgraph:
|
||
.then(function(task){ | ||
if (!_.isEmpty(task) && _.has(task[0], 'graphId')){ | ||
return waterline.graphobjects.find({instanceId: task[0].graphId}) | ||
.then(function(graphObject){ | ||
//TODO: workflow progress percentage should be designed | ||
progressData = { | ||
graphId: graphObject[0].instanceId, | ||
graphName: graphObject[0].definition.friendlyName, | ||
progress: { | ||
percentage: "na", | ||
description: data.progress.description | ||
}, | ||
taskProgress: { | ||
graphId: graphObject[0].instanceId, | ||
taskId: data.taskId, | ||
taskName: graphObject[0].tasks[data.taskId].friendlyName, | ||
progress: data.progress | ||
} | ||
}; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. suggest to return something in this .then block. One option would be combine following then block with this one. |
||
}) | ||
.then(function(){ | ||
return TaskGraph.prototype.updateGraphProgress(progressData); | ||
}); | ||
} else { | ||
logger.error('notification API fails', { | ||
progress: data, | ||
error: "Can't find active task for given taskId" | ||
}); | ||
} | ||
}); | ||
}; | ||
|
||
return new NotificationApiService(); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would suggest to refactor this to following so other develops can choose to develop other task notifications other than progress notification.