var logger = JL('mic.js');
var Mic = {};
-var ps = null;
+
+/**
+ * Process Manager
+ * ObjectArray
+ * processMgr = {
+ * 'jobId': jobId,
+ * 'jobProcessId': pid
+ * });
+ */
+var processMgr = [];
Mic.isAvailable = function isAvailable() {
- return (ps === null);
+ if (processMgr.length > 0 && processMgr.length <= 4) {
+ return true;
+ }
+ return false;
}
-Mic.kill = function kill() {
- if (ps === null) {
+Mic.kill = function kill(paramObj) {
+ var strJobId, psIndex, psObj, psId;
+ logger.info('MIC Kill: paramObj = ' + JSON.stringify(paramObj));
+
+ if (this.isAvailable() === false) {
return;
}
- TreeKill(ps.pid, 'SIGKILL');
- ps = null;
+
+ strJobId = paramObj.jobId;
+
+ psIndex = _.findIndex(processMgr, function (o) {
+ return o.jobId == strJobId;
+ })
+
+ if (psIndex < 0) {
+ return;
+ }
+ psObj = processMgr[psIndex];
+ psId = psObj.jobProcessId;
+
+ TreeKill(psId, 'SIGKILL');
+ processMgr.pop(psIndex);
}
-Mic.process = function process(command, callback) {
+Mic.process = function process(command, callback, jobId) {
+ var ps;
+
// execution
ps = exec(command);
+ // Process Manager - add
+ processMgr.push({
+ 'jobId': jobId,
+ 'jobProcessId': ps.pid
+ });
+
ps.stdout.on('data', callback.stdout || function (out) {
process.stdout.write(out);
});
sendMsg(AppConfig.EVENT.SOCKET.FS_IMAGE_ADD_FAIL, 'Failed (' + code + ')');
},
exit: function (code) {
- // code is the final exit code of the process, otherwise null
- ps = null;
+ // code is the final exit code of the process
+ var psIndex = _.findIndex(processMgr, function (o) {
+ return o.jobId == strJobId;
+ });
+ if (psIndex >= 0) {
+ processMgr.pop(psIndex);
+ }
+
logger.error('Terminated (' + code + ')');
if (code === 0) {
sendMsg(AppConfig.EVENT.SOCKET.FS_IMAGE_ADD_FINISH, {
});
}
}
- }
+ },
+ paramObj.jobId
);
};
// bind events - cancel button
$('#tic-job-table a.btncancel').on('click', function (e) {
+ var msgData, jobId;
e.preventDefault();
+
$(this).addClass('btnnotactive');
- client.emit(AppConfig.EVENT.SOCKET.FS_IMAGE_ADD_KILL);
+
+ jobId = $(this).data('jobid');
+ msgData = {
+ jobId: jobId
+ };
+
+ client.emit(AppConfig.EVENT.SOCKET.FS_IMAGE_ADD_KILL, msgData);
});
}
});
'<td><a class="tic-job-list-btn btndownload btnnotactive">Download</a></td>',
'<td><%= jobImageSize %></td>',
'<td><%= jobUptime %></td>',
- '<td><a class="tic-job-list-btn btncancel <%= classJobCancel %>" title="Cancel">Cancel</a></td>',
+ '<td><a class="tic-job-list-btn btncancel <%= classJobCancel %>" data-jobid="<%= jobNum %>" title="Cancel">Cancel</a></td>',
'<td><a class="tic-job-list-btn <%= classJobKsPath %>" href="<%= jobKsPath %>" title="Kickstarter File">KS</a></td>',
'<td><a class="tic-job-list-btn" href="<%= jobLogPath %>" title="Log">Log</a></td>',
'</tr>',