From 57d4272282377bd49fac6944edcdadf7d9346b50 Mon Sep 17 00:00:00 2001 From: Mitar Date: Sun, 19 Feb 2017 03:13:45 -0800 Subject: [PATCH 1/2] Support custom functions for scheduling repeated jobs. --- src/shared.coffee | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/shared.coffee b/src/shared.coffee index 2e23889..7618f5e 100644 --- a/src/shared.coffee +++ b/src/shared.coffee @@ -797,9 +797,12 @@ class JobCollectionBase extends Mongo.Collection doc.retryUntil = time if doc.retryUntil < time doc.repeatUntil = time if doc.repeatUntil < time + if @scheduleRepeat? doc + # There is a custom hook to process repeatWait defined, and it returned true + # to signal that it processed the doc (potentially setting doc.after to a new value). # 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' unless next = @later?.schedule(doc.repeatWait).next(1, doc.after) console.warn "No valid available later.js times in schedule after #{doc.after}" return null From 98e2a2de1106731ea9d96da6f238f3bb7c3965f2 Mon Sep 17 00:00:00 2001 From: Mitar Date: Sun, 19 Mar 2017 03:35:00 -0700 Subject: [PATCH 2/2] Also allow scheduling next iterations. --- src/shared.coffee | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/shared.coffee b/src/shared.coffee index 7618f5e..6a4f64f 100644 --- a/src/shared.coffee +++ b/src/shared.coffee @@ -797,9 +797,13 @@ class JobCollectionBase extends Mongo.Collection doc.retryUntil = time if doc.retryUntil < time doc.repeatUntil = time if doc.repeatUntil < time - if @scheduleRepeat? doc - # There is a custom hook to process repeatWait defined, and it returned true + 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 else if @later? and typeof doc.repeatWait isnt 'number' @@ -1050,7 +1054,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