@@ -254,32 +254,33 @@ class Job extends EventEmitter {
254254
255255 this . _json . next = next . getTime ( ) ;
256256 }
257- if ( this . name !== "alerts:monitor" ) {
258- //check if any job already scheduled or running
259- let query = {
260- status : { "$in" : [ STATUS . SCHEDULED , STATUS . RUNNING ] } ,
261- name : this . name ,
262- } ;
263- if ( this . _id ) {
264- query . _id = { $ne : this . _id } ;
265- }
266- var self = this ;
267- return new Promise ( ( resolve , reject ) => {
268- Job . findMany ( this . db ( ) , query ) . then ( existing => {
269- if ( existing && existing . length ) {
270- log . d ( 'Job already scheduled or running: %j' , existing ) ;
271- this . _json . status = STATUS . CANCELLED ; //set this as cancelled now as we have other scheduled
272- }
273- else {
274- self . _save ( ) . then ( resolve , reject ) ;
275- }
276257
277- } ) ;
278- } ) ;
258+ //check if any job already scheduled or running
259+ let query = {
260+ status : { "$in" : [ STATUS . SCHEDULED , STATUS . RUNNING ] } ,
261+ name : this . name ,
262+ } ;
263+
264+ if ( this . name === 'alerts:monitor' && this . data && Object . keys ( this . data ) . length ) {
265+ query . data = this . data ;
279266 }
280- else {
281- return this . _save ( ) ;
267+
268+ if ( this . _id ) {
269+ query . _id = { $ne : this . _id } ;
282270 }
271+
272+ var self = this ;
273+ return new Promise ( ( resolve , reject ) => {
274+ Job . findMany ( this . db ( ) , query ) . then ( existing => {
275+ if ( existing && existing . length ) {
276+ log . d ( 'Job already scheduled or running: %j' , existing ) ;
277+ this . _json . status = STATUS . CANCELLED ; //set this as cancelled now as we have other scheduled
278+ }
279+ else {
280+ self . _save ( ) . then ( resolve , reject ) ;
281+ }
282+ } ) ;
283+ } ) ;
283284 }
284285
285286 /**
@@ -1142,4 +1143,4 @@ module.exports = {
11421143 STATUS : STATUS ,
11431144 STATUS_MAP : STATUS_MAP ,
11441145 debounce : debounce
1145- } ;
1146+ } ;
0 commit comments