Skip to content

Commit 06361bf

Browse files
committed
Improve and document Jobs.find()
1 parent 5526204 commit 06361bf

File tree

2 files changed

+31
-2
lines changed

2 files changed

+31
-2
lines changed

DOCUMENTATION.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ Steve Jobs is an all inclusive package for scheduling background jobs. It automa
55
- [Jobs.configure](#jobsconfigure)
66
- [Jobs.register](#jobsregister)
77
- [Jobs.run](#jobsrun)
8+
- [Jobs.find](#jobsfind)
89
- [Jobs.execute](#jobsexecute)
910
- [Jobs.reschedule](#jobsreschedule)
1011
- [Jobs.replicate](#jobsreplicate)
@@ -164,6 +165,30 @@ The configuration object supports the following inputs:
164165
- **`callback`** - Function
165166
- Run a callback function after scheduling the job
166167

168+
### Jobs.find
169+
170+
`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`.
171+
172+
```javascript
173+
Jobs.find("sendReminder", "[email protected]", "The future is here!", function (jobDoc) {
174+
if (jobDoc) {
175+
this.reschedule({
176+
in: {
177+
minutes: 5
178+
}
179+
});
180+
181+
return jobDoc;
182+
} else {
183+
this.run({
184+
in: {
185+
minutes: 5
186+
}
187+
})
188+
}
189+
});
190+
```
191+
167192
### Jobs.execute
168193

169194
`Jobs.execute` allows you to run a job ahead of its due date. It can only work on jobs that have not been resolved.

package/server/imports/actions/find/process.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,12 @@ import { Utilities } from "../../utilities"
22
import { toolbelt } from "./toolbelt.js"
33

44
var process = function (doc, callback) {
5-
var Toolbelt = new toolbelt(doc);
6-
5+
var Toolbelt;
6+
7+
if (typeof doc === "object") {
8+
Toolbelt = new toolbelt(doc);
9+
}
10+
711
try {
812
var jobResult = callback.apply(Toolbelt, [doc]);
913
}

0 commit comments

Comments
 (0)