You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+13-7
Original file line number
Diff line number
Diff line change
@@ -95,7 +95,7 @@ try {
95
95
this.add(5000, data);
96
96
}
97
97
98
-
// Don't forget to clean up later: `dt.stop()`
98
+
// Don't forget to clean up later: `dt.stop()` or `dt.close()`, as applicable
99
99
```
100
100
101
101
@@ -113,21 +113,25 @@ The constructor takes a single object. Properties are as follows:
113
113
|`callback`| The function to call when tasks are due. <br><br>When a task is due or past-due, your callback method is called asynchronously, passing the `data` you provided when adding, the generated `taskId`, and the time (in ms) that the task was due.<br><br>The context of `this` is the `DelayedTasks` object. | Yes ||
114
114
|`options.pollIntervalMs`| How often to poll redis for tasks due (in milliseconds). The shorter the interval, the sooner after being due a task will be processed, but the more load in redis. | No | 1000 |
115
115
116
-
<sup>1</sup> This module uses [`node-redis`](https://github.com/redis/node-redis) version 4 under the hood in legacy mode.
116
+
<sup>1</sup> This module uses [`node-redis`](https://github.com/redis/node-redis) version 4 under the hood in legacy mode. If you provide your own client, you're responsible for connecting, disconnecting, and creating an error handler.
117
117
118
118
### Connect
119
119
120
-
Before doing anything, call `await dt.connect()` to connect to redis.
120
+
If you provided an object with options for connecting to redis, you must call `await dt.connect()` to connect to redis before doing anything else. If you've provided an existing, connected redis client, this is not necessary.
121
121
122
122
### start / stop polling
123
123
124
-
To begin polling for tasks, call `dt.start()`. Call `dt.stop()` to stop future polling.
124
+
To begin polling for tasks, call `dt.start()`. This returns a boolean with the status of starting. If `false`, it's because the redis client hasn't been connected yet. If this was a self-supplied client, call `await client.connect()`. Otherwise, call `await dt.connect()` to create the connection.
125
+
126
+
Call `dt.stop()` to stop future polling.
125
127
126
128
### close()
127
129
128
-
Calling `dt.close()` will stop polling and close the redis client being used.
130
+
Calling `await dt.close()` will stop polling. If a new redis client was created for the object instance (that is, it was passed an object of configuration details), that redis client will be closed, too (using `disconnect()` to abort pending requests). If you passed an existing redis client to the constructor, it will be left open and you'll have to close it yourself when you're finished with it.
129
131
130
-
**CAUTION:** If you passed your own redis client in the constructor, that client will be closed with this command. If you just want to stop polling, but leave the connection open, call `dt.stop()` instead.
132
+
This returns a promise that resolves when the client connection is confirmed closed.
133
+
134
+
If you just want to stop polling, but leave the connection open, call `dt.stop()` instead.
131
135
132
136
### add(_delayMs_, _data_)
133
137
@@ -151,7 +155,7 @@ To force a poll outside of the poll interval, call `dt.poll()`. This should be u
151
155
152
156
## Testing
153
157
154
-
Start a local redis server on port 6379. You can run `docker-compose up` to launch one from this repo. Once redis is running, run `npm test` or `npm coverage`.
158
+
The test suite requires a local redis server on port 6379. You can run `docker-compose up` to launch one from this repo. Once redis is running, run `npm test` or `npm coverage`.
155
159
156
160
## Notes
157
161
@@ -181,5 +185,7 @@ catch everything, including redis errors.
181
185
182
186
* Better handling of watch conflicts in `dt.poll`. Right now it just quits, but if this happens a lot, nothing would end up getting processed.
183
187
188
+
* Find a redis mock that works with `node-redis` v4 and later versions of redis server.
0 commit comments