diff --git a/src/shared.coffee b/src/shared.coffee index 8fefdd2..8f675d5 100644 --- a/src/shared.coffee +++ b/src/shared.coffee @@ -871,9 +871,16 @@ class JobCollectionBase extends Mongo.Collection doc.retryUntil = time if doc.retryUntil < time doc.repeatUntil = time if doc.repeatUntil < time + if warning = @scheduleRepeatFirst? doc + # There is a custom hook defined to process repeatWait, and it returned true + # to signal that it processed the doc (potentially setting doc.after to a new value). + # If the returned value is a string, it is used as a warning and further execution stops. + if typeof warning is 'string' + console.warn warning + return null # If doc.repeatWait is a later.js object, then don't run before # the first valid scheduled time that occurs after doc.after - if @later? and typeof doc.repeatWait isnt 'number' + else if @later? and typeof doc.repeatWait isnt 'number' # Using a workaround to find next time after doc.after. # See: https://github.com/vsivsi/meteor-job-collection/issues/217 schedule = @later?.schedule(doc.repeatWait) @@ -1126,7 +1133,12 @@ class JobCollectionBase extends Mongo.Collection ) if num is 1 if doc.repeats > 0 - if typeof doc.repeatWait is 'number' + if jobId = @scheduleRepeatNext? doc + # There is a custom hook defined to process repeatWait, and it returned jobId + # to signal that it processed the doc (potentially by calling @_rerun_job). + # If jobId is literally true, then we just do not process repeating further. + jobId = undefined if jobId is true + else if typeof doc.repeatWait is 'number' if doc.repeatUntil - doc.repeatWait >= time jobId = @_rerun_job doc else