@@ -66,80 +66,6 @@ taskmanager.longtask = function(options) {
66
66
var start = new Date ( ) . getTime ( ) ;
67
67
var timeout ;
68
68
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
-
143
69
/** switching to long task */
144
70
function switchToLongTask ( ) {
145
71
timeout = null ;
@@ -1030,47 +956,7 @@ taskmanager.rerunTask = function(options, callback) {
1030
956
} ;
1031
957
1032
958
taskmanager . stopTask = function ( options , callback ) {
1033
- options . db = options . db || common . db ;
1034
-
1035
- /**
1036
- * Stop task
1037
- * @param {object } op_id - operation id for mongo process
1038
- * @param {object } options1.db - database connection
1039
- * @param {string } options1.id - id of the task result
1040
- * @param {object } reqData - request data
1041
- * @param {funciton } callback1 - callback for the result
1042
- */
1043
- function stopTask ( op_id ) {
1044
- common . db . admin ( ) . command ( { killOp : 1 , op : Number . parseInt ( op_id ) } , function ( error , result ) {
1045
- if ( result . ok === 1 ) {
1046
- callback ( null , "Success" ) ;
1047
- }
1048
- else {
1049
- callback ( null , "Operation could not be stopped" ) ;
1050
- }
1051
- } ) ;
1052
- }
1053
-
1054
- options . db . collection ( "long_tasks" ) . findOne ( { _id : options . id } , function ( err , res ) {
1055
- if ( res ) {
1056
- if ( res . creator ) {
1057
- options . db . collection ( "members" ) . findOne ( { _id : common . db . ObjectID ( res . creator ) } , function ( err1 , member ) {
1058
- if ( member ) {
1059
- stopTask ( res . op_id ) ;
1060
- }
1061
- else {
1062
- callback ( null , "No permission to stop this task" ) ;
1063
- }
1064
- } ) ;
1065
- }
1066
- else {
1067
- stopTask ( res . op_id ) ;
1068
- }
1069
- }
1070
- else {
1071
- callback ( null , "Task does not exist" ) ;
1072
- }
1073
- } ) ;
959
+ callback ( null , "Operation could not be stopped" ) ;
1074
960
} ;
1075
961
1076
962
/**
@@ -1113,4 +999,4 @@ function getResult(callback, options) {
1113
999
}
1114
1000
} ;
1115
1001
}
1116
- module . exports = taskmanager ;
1002
+ module . exports = taskmanager ;
0 commit comments