Skip to content

Commit

Permalink
Improve and document Jobs.find()
Browse files Browse the repository at this point in the history
  • Loading branch information
msavin committed Jul 8, 2019
1 parent 5526204 commit 06361bf
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
25 changes: 25 additions & 0 deletions DOCUMENTATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Steve Jobs is an all inclusive package for scheduling background jobs. It automa
- [Jobs.configure](#jobsconfigure)
- [Jobs.register](#jobsregister)
- [Jobs.run](#jobsrun)
- [Jobs.find](#jobsfind)
- [Jobs.execute](#jobsexecute)
- [Jobs.reschedule](#jobsreschedule)
- [Jobs.replicate](#jobsreplicate)
Expand Down Expand Up @@ -164,6 +165,30 @@ The configuration object supports the following inputs:
- **`callback`** - Function
- Run a callback function after scheduling the job

### Jobs.find

`Jobs.find` allows you to find a single pending job by its arguments, and run logic against it. You can pass in a callback in the end to check for the document, and you can run the same operations with-in the function scope as you would with `Jobs.register`, as well as `this.run` as a shortcut to `Jobs.run`.

```javascript
Jobs.find("sendReminder", "[email protected]", "The future is here!", function (jobDoc) {
if (jobDoc) {
this.reschedule({
in: {
minutes: 5
}
});

return jobDoc;
} else {
this.run({
in: {
minutes: 5
}
})
}
});
```

### Jobs.execute

`Jobs.execute` allows you to run a job ahead of its due date. It can only work on jobs that have not been resolved.
Expand Down
8 changes: 6 additions & 2 deletions package/server/imports/actions/find/process.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@ import { Utilities } from "../../utilities"
import { toolbelt } from "./toolbelt.js"

var process = function (doc, callback) {
var Toolbelt = new toolbelt(doc);

var Toolbelt;

if (typeof doc === "object") {
Toolbelt = new toolbelt(doc);
}

try {
var jobResult = callback.apply(Toolbelt, [doc]);
}
Expand Down

0 comments on commit 06361bf

Please sign in to comment.