Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support custom functions for scheduling repeated jobs #216

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions src/shared.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down