Skip to content

Commit ad0c514

Browse files
committed
Improved documentation
1 parent 1a5bc47 commit ad0c514

File tree

2 files changed

+78
-2
lines changed

2 files changed

+78
-2
lines changed

DOCUMENTATION.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,39 @@ Steve Jobs is an all inclusive package for scheduling background jobs. It automa
1616
- [Jobs.remove](#jobsremove)
1717
- [Jobs.collection](#jobscollection)
1818

19+
20+
### Overview of a Job Document
21+
22+
Every Job document in stored into MongoDB because MongoDB has great persistence and querying features, and because you would not be required to set up any additional services to get running.
23+
24+
Here is an example of what a jobs document looks like:
25+
26+
```js
27+
{
28+
_id: "riEauLYngjSGoETWh",
29+
name: "sendEmail",
30+
created: 2019-01-13T14:24:42.444Z,
31+
serverId: "R7KPMHWz7DEsDWBCm",
32+
state: "success",
33+
due: 2019-01-13T14:24:51.444Z,
34+
priority: 0,
35+
arguments: ["sendReminder", "[email protected]", "The future is here!"],
36+
history: [{
37+
date: 2019-01-13T14:24:51.444Z,,
38+
state: "success",
39+
serverId: "R7KPMHWz7DEsDWBCm"
40+
}, {
41+
date: 2019-01-13T14:23:51.444Z,
42+
type: "reschedule",
43+
serverId: "5whJ8rWzDcTv8aZGy",
44+
newDue: 2019-01-13T14:24:51.444Z
45+
}]
46+
}
47+
```
48+
49+
The history of each job is kept in the `history` field, which can also hold the result of the job, if you pass it into the `success` or `failure` action.
50+
51+
1952
### Jobs.configure
2053

2154
`Jobs.configure` allows you to configure how the package should work. You can figure one option or all of them. All the options are pre-configured in [`./package/server/imports/utilities/config.js`](https://github.com/msavin/SteveJobs..meteor.jobs.scheduler.queue.background.tasks/blob/master/package/server/imports/utilities/config/index.js).

README.md

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,17 @@ Then, write your background jobs like you would write your methods:
4141
```javascript
4242
Jobs.register({
4343
"sendReminder": function (to, message) {
44+
var instance = this;
45+
4446
var call = HTTP.put("http://www.magic.com/sendEmail", {
4547
to: to,
4648
message: message
4749
})
4850

4951
if (call.statusCode === 200) {
50-
this.success(call.result);
52+
instance.success(call.result);
5153
} else {
52-
this.reschedule({
54+
instance.reschedule({
5355
in: {
5456
minutes: 5
5557
}
@@ -82,6 +84,47 @@ Jobs.run("sendReminder", "[email protected]", "The future is here!", {
8284

8385
The configuration object supports `date`, `in`, `on`, `priority`, `singular`, `unique`, and `data`, all of which are completely optional. For more information, see the `Jobs.run` <a href="https://github.com/msavin/SteveJobs..meteor.jobs.scheduler.queue.background.tasks/blob/master/DOCUMENTATION.md#jobsrun">documentation</a>.
8486

87+
## Repeating Jobs
88+
89+
Creating repeating jobs is easy, and you have total control over how they run. First, you need to create a job that will automatically replicate itself.
90+
91+
```javascript
92+
Jobs.register({
93+
"syncData": function () {
94+
var instance = this;
95+
96+
var call = HTTP.put("http://www.magic.com/syncData")
97+
98+
if (call.statusCode === 200) {
99+
instance.replicate({
100+
in: {
101+
hours: 1
102+
}
103+
});
104+
105+
// alternatively, you can use instance.remove to save storage
106+
instance.success(call.result);
107+
} else {
108+
instance.reschedule({
109+
in: {
110+
minutes: 5
111+
}
112+
});
113+
}
114+
}
115+
});
116+
```
117+
118+
Then, schedule the job to run with the `singular` flag, only if an instance of it does not exist.
119+
120+
```javascript
121+
Meteor.startup(function () {
122+
Jobs.run("syncData", {
123+
singular: true
124+
})
125+
})
126+
```
127+
85128
## Documentation
86129

87130
`Jobs.register` and `Jobs.run` are all you need to get started, but that's only the beginning of what the package can do. To explore the rest of the functionality, jump into the documentation:

0 commit comments

Comments
 (0)