Skip to content

Commit

Permalink
[README]: added instructions about recurring task initialization
Browse files Browse the repository at this point in the history
  • Loading branch information
nathanschwarz committed Feb 18, 2021
1 parent 7a18f48 commit 6c46fed
Showing 1 changed file with 22 additions and 3 deletions.
25 changes: 22 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -195,14 +195,33 @@ in such case your overall system should be **slowed down** because some of the p
```
import { add } from 'date-fns/date' // external library to handle date objects
function schedTask(job) {
function recurringTask(job) {
// do something
const dueDate = add(new Date(), { minutes: 10 })
TaskQueue.addTask({ taskType: 'schedTask', priority: 1, data: {}, dueDate })
TaskQueue.addTask({ taskType: 'recurringTask', priority: 1, data: {}, dueDate })
}
const taskMap = {
schedTask
recurringTask
}
```

Because the next recurring task is kept in the queue, if the server is restarted, it will start the recurring task again.
Be sure to remove all recurring task *on the master* before starting others, or lock the insert :

You can either do :

`Meteor.startup(() => {
if (Cluster.isMaster()) {
TaskQueue.remove({ tasType: 'recurringTask' })
}
})`

or at task *initialization* :
```
const recurringTaskExists = TaskQueue.findOne({ taskType: 'recurringTask' }) !== undefined
if (!recurringTaskExists) {
TaskQueue.addtask({ taskType: 'recurringTask', priority: 1, data: {}, dueDate })
}
```

Expand Down

0 comments on commit 6c46fed

Please sign in to comment.