Skip to content

Commit 0764b43

Browse files
author
Cihad Tekin
committed
[core] taskmanager: removed the ability to stop a mongo operation for singlestore
1 parent 6e8ff1d commit 0764b43

File tree

3 files changed

+1
-162
lines changed

3 files changed

+1
-162
lines changed

api/utils/requestProcessor.js

-11
Original file line numberDiff line numberDiff line change
@@ -828,17 +828,6 @@ const processRequest = (params) => {
828828
});
829829
});
830830
break;
831-
case 'stop':
832-
validateUserForWrite(params, () => {
833-
taskmanager.stopTask({
834-
db: common.db,
835-
id: params.qstring.task_id,
836-
op_id: params.qstring.op_id
837-
}, (err, res) => {
838-
common.returnMessage(params, 200, res);
839-
});
840-
});
841-
break;
842831
case 'delete':
843832
validateUserForWrite(params, () => {
844833
taskmanager.deleteResult({

api/utils/taskmanager.js

+1-122
Original file line numberDiff line numberDiff line change
@@ -58,88 +58,14 @@ const log = require('./log.js')('core:taskmanager');
5858
* }, outputData:function(err, data){
5959
* common.returnOutput(params, data);
6060
* }
61-
* }));
61+
* }));
6262
*/
6363
taskmanager.longtask = function(options) {
6464
options.db = options.db || common.db;
6565
var exceeds = false;
6666
var start = new Date().getTime();
6767
var timeout;
6868

69-
var saveOpId = async function(comment_id, retryCount) {
70-
common.db.admin().command({ currentOp: 1 }, async function(error, result) {
71-
if (error) {
72-
log.d(error);
73-
return;
74-
}
75-
else {
76-
if (result && result.inprog) {
77-
for (var i = 0; i < result.inprog.length; i++) {
78-
let op = result.inprog[i];
79-
if (!('$truncated' in op.command) && (i !== result.inprog.length - 1)) {
80-
continue;
81-
}
82-
if (!('$truncated' in op.command) && (i === result.inprog.length - 1)) {
83-
if (retryCount < 3) {
84-
setTimeout(() => saveOpId(comment_id, (++retryCount)), 500);
85-
return;
86-
}
87-
else {
88-
log.d(`operation not found for task:${options.id} comment: ${comment_id}`);
89-
break;
90-
}
91-
}
92-
93-
let comment_position = op.command.$truncated.indexOf('$comment');
94-
if (comment_position === -1) {
95-
continue;
96-
}
97-
98-
let substr = op.command.$truncated.substring(comment_position, op.command.$truncated.length) || "";
99-
var comment_val = "";
100-
substr = substr.match(/"(.*?)"/);
101-
if (substr && Array.isArray(substr)) {
102-
comment_val = substr[1];
103-
}
104-
105-
if (comment_val === comment_id) {
106-
var task_id = options.id;
107-
var op_id = op.opid;
108-
await common.db.collection("long_tasks").findOneAndUpdate({ _id: common.db.ObjectID(task_id) }, { $set: { op_id: op_id } });
109-
log.d(`Operation found task: ${task_id} op:${op_id} comment: ${comment_id}`);
110-
break;
111-
}
112-
else if ((comment_val !== comment_id) && (i === (result.inprog.length - 1))) {
113-
if (retryCount < 3) {
114-
setTimeout(() => saveOpId(comment_id, (++retryCount)), 500);
115-
break;
116-
}
117-
else {
118-
log.d(`operation not found for task:${options.id} comment: ${comment_id}`);
119-
break;
120-
}
121-
}
122-
}
123-
}
124-
}
125-
});
126-
};
127-
128-
if (options.comment_id) {
129-
var retryCount = 0;
130-
try {
131-
saveOpId(options.comment_id, retryCount);
132-
}
133-
catch (err) {
134-
if (retryCount < 3) {
135-
setTimeout(() =>saveOpId(options.comment_id, ++retryCount), 500);
136-
}
137-
else {
138-
console.log(err);
139-
}
140-
}
141-
}
142-
14369
/** switching to long task */
14470
function switchToLongTask() {
14571
timeout = null;
@@ -298,9 +224,6 @@ taskmanager.createTask = function(options, callback) {
298224
update.subtask_key = options.subtask_key || "";
299225
update.taskgroup = options.taskgroup || false;
300226
update.linked_to = options.linked_to;
301-
if (options.comment_id) {
302-
update.comment_id = options.comment_id;
303-
}
304227
if (options.subtask && options.subtask !== "") {
305228
update.subtask = options.subtask;
306229
var updateSub = {$set: {}};
@@ -1117,50 +1040,6 @@ taskmanager.rerunTask = function(options, callback) {
11171040
});
11181041
};
11191042

1120-
taskmanager.stopTask = function(options, callback) {
1121-
options.db = options.db || common.db;
1122-
1123-
/**
1124-
* Stop task
1125-
* @param {object} op_id - operation id for mongo process
1126-
* @param {object} options1.db - database connection
1127-
* @param {string} options1.id - id of the task result
1128-
* @param {object} reqData - request data
1129-
* @param {funciton} callback1 - callback for the result
1130-
*/
1131-
function stopTask(op_id) {
1132-
common.db.admin().command({ killOp: 1, op: Number.parseInt(op_id) }, function(error, result) {
1133-
if (result.ok === 1) {
1134-
callback(null, "Success");
1135-
}
1136-
else {
1137-
callback(null, "Operation could not be stopped");
1138-
}
1139-
});
1140-
}
1141-
1142-
options.db.collection("long_tasks").findOne({ _id: options.id }, function(err, res) {
1143-
if (res) {
1144-
if (res.creator) {
1145-
options.db.collection("members").findOne({ _id: common.db.ObjectID(res.creator) }, function(err1, member) {
1146-
if (member) {
1147-
stopTask(res.op_id);
1148-
}
1149-
else {
1150-
callback(null, "No permission to stop this task");
1151-
}
1152-
});
1153-
}
1154-
else {
1155-
stopTask(res.op_id);
1156-
}
1157-
}
1158-
else {
1159-
callback(null, "Task does not exist");
1160-
}
1161-
});
1162-
};
1163-
11641043
/**
11651044
* Create a callback for getting result, including checking gridfs
11661045
* @param {function} callback - callback for the result

frontend/express/public/core/report-manager/javascripts/countly.views.js

-29
Original file line numberDiff line numberDiff line change
@@ -127,9 +127,6 @@
127127
canDeleteReport: function() {
128128
return countlyGlobal.member.global_admin || countlyGlobal.admin_apps[countlyCommon.ACTIVE_APP_ID];
129129
},
130-
canStopReport: function() {
131-
return countlyGlobal.member.global_admin || countlyGlobal.admin_apps[countlyCommon.ACTIVE_APP_ID];
132-
},
133130
query: function() {
134131
var q = {};
135132
if (this.fixedOrigin) {
@@ -316,14 +313,6 @@
316313
isDownloadable: function(row) {
317314
return ["views", "dbviewer", "tableExport"].includes(row.type);
318315
},
319-
isStopable: function(row) {
320-
if (row.status === "running" && row.op_id && row.comment_id) {
321-
return true;
322-
}
323-
else {
324-
return false;
325-
}
326-
},
327316
isReadyForView: function(row) {
328317
if (row.linked_to) {
329318
if (row.have_dashboard_widget) {
@@ -342,7 +331,6 @@
342331
},
343332
handleCommand: function(command, row) {
344333
var id = row._id,
345-
op_id = row.op_id,
346334
self = this;
347335

348336
if (id) {
@@ -378,23 +366,6 @@
378366
});
379367
}, [CV.i18n("common.no-dont-do-that"), CV.i18n("taskmanager.yes-rerun-task")], {title: CV.i18n("taskmanager.confirm-rerun-title"), image: "rerunning-task"});
380368
}
381-
else if (command === "stop-task") {
382-
CountlyHelpers.confirm(CV.i18n("taskmanager.confirm-stop"), "popStyleGreen", function(result) {
383-
if (!result) {
384-
return true;
385-
}
386-
self.refresh();
387-
countlyTaskManager.stop(id, op_id, function(res, error) {
388-
if (res.result === "Success") {
389-
countlyTaskManager.monitor(id, true);
390-
self.refresh();
391-
}
392-
else {
393-
CountlyHelpers.alert(error, "red");
394-
}
395-
});
396-
}, [CV.i18n("common.no-dont-do-that"), CV.i18n("taskmanager.yes-stop-task")], {title: CV.i18n("taskmanager.confirm-stop-title"), image: "rerunning-task"});
397-
}
398369
else if (command === "view-task") {
399370
self.$emit("view-task", row);
400371
if (!this.disableAutoNavigationToTask) {

0 commit comments

Comments
 (0)