Skip to content

Commit 144bf5b

Browse files
committed
Renamed QueueMgr class to Channel. Renamed WorkQueueBroker class to WorkQueueMgr.
Updated test and demo code to use the new class names. Hopefully, the new class names make better sense. The README.md file has been split up into several separate files to improve readability. No functionality has been changed since the previous version.
1 parent eb13450 commit 144bf5b

8 files changed

+963
-0
lines changed

CHANGE_LOG.md

+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
##Change Log
2+
3+
**v0.0.0**: Initial version.
4+
5+
**v0.0.1-3**: Changes to README.md. Implementation of jasmine-node tests.
6+
7+
**v0.1.2**: Refactored to implement new QueueMgr and WorkQueueBroker interfaces; Implementation of connection strategies.
8+
9+
**v0.1.3**: Further Refactoring to implement new QueueMgr and WorkQueueBroker interfaces;
10+
Merged v0.1.3 from flex branch into master.
11+
12+
**v0.1.4**: Fix for issue #1 - Where to find redis-queue-config file is too restrictive - Now uses
13+
QUEUE_CONFIG_FILE environment variable to find the config file;
14+
An alternative is to specify the config file path in the queueMgr or workQueueBroker constructor.
15+
Changed testing from Jasmine to Mocha.; Implemented Mocha tests;
16+
Introduced interleaved tests.
17+
18+
**v0.1.5**: Various comment and README.md changes;
19+
Corrected error in provision of Redis Cloud hostname;
20+
21+
**v0.1.6**: Compiled to capture latest mod to .coffee source.
22+
23+
**v0.1.7**: Fix for issue #4 - Stall occurs when one of two work queues on same connection becomes empty.
24+
25+
**v0.1.8**: Fix for REDISCLOUD_URL having no auth field; Created change log in README.md.
26+
27+
**v0.1.9**: Added usage examples to README.md for WorkQueueBroker. Added commandQueueLength function
28+
to permit some rudimentary control of backpressure. Documented 'drain' event.
29+
30+
**v0.1.10**: Changed `grunt test` to use mocha rather than jasmine-node. Improved usage documentation.
31+
32+
**v0.1.11**: Added shutdownSoon function to QueueMgr and WorkQueueBroker. Improved README.md and demos. Made test suite
33+
use unique queue names to prevent interference from demos.
34+
35+
**v0.1.12**: Modified WorkQueueMgr to preserve the order of
36+
queue names used when calling popAny. ECMA-262 5.1 (15.2.3.14 Object.keys and 12.6.4 The for-in Statement) does not
37+
specify enumeration order, so an array should be used. Also, see: https://code.google.com/p/v8/issues/detail?id=164
38+
39+
**v0.1.13**: Modified connStrategyBlueMixRedisCloud to use a configured redis version. Added config info to README.md.
40+
41+
**v0.1.14**: Added 'clean' task to Gruntfile. Fixed some potential problems found by jshint. Tidied Gruntfile.
42+
Replaced some URLs in the demo source that were no longer working (404 not found).
43+
44+
**v0.1.15**: Send now checks that queue has not been destroyed.
45+
Added 'compile-test' task to Gruntfile. Fixed
46+
incorrect calls to isValidQueueName. Added tests for WorkQueue
47+
exceptions. Grunt now uses grunt-mocha-test plugin for better
48+
reporting.
49+
50+
**v0.1.16**: Reverted WorkQueue behaviour back to previous version since v0.1.15 change was too restrictive.
51+
Added destroy function to WorkQueue. Updated README.md with info about the new destroy function. Also, added
52+
some architecture notes.
53+
54+
**v0.1.17**: Added ability to schedule parallel jobs in the consume function via an optional arity parameter.
55+
Added @outstanding to queueMgr class. worker04 example uses a second WorkQueueBroker instance when arity is
56+
greater than 1 to send result back to provider04.
57+
58+
**v0.2.0**: Renamed QueueMgr class to Channel. Renamed WorkQueueBroker class to WorkQueueMgr. Updated test
59+
and demo code to use the new class names, which have been adopted to correspond better to what they represent.
60+
The README.md file has been split up into several separate files to improve readability.
61+

COFFEESCRIPT_USAGE_EXAMPLES.md

+159
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
1+
###Channel Coffescript Usage Example
2+
3+
1. Ensure you have a Redis server installed and running. For example, once installed, you can run it locally by
4+
5+
redis-server &
6+
7+
1. Require `node-redis-queue` Channel
8+
9+
Channel = require('node-redis-queue').Channel
10+
11+
1. Create a Channel instance and connect to Redis
12+
13+
channel = new Channel()
14+
channel.connect ->
15+
console.log 'ready'
16+
myMainLogic()
17+
18+
Alternatively, you can provide an existing Redis connection (i.e., a redis client instance)
19+
20+
channel.attach redisConn
21+
22+
1. Optionally, handle error events
23+
24+
channel.on 'error', (error) ->
25+
console.log 'Stopping due to: ' + error
26+
process.exit()
27+
28+
1. Optionally, handle lost connection events
29+
30+
channel.on 'end', ->
31+
console.log 'Connection lost'
32+
33+
1. Optionally, clear previous data from the queue, providing a callback
34+
to handle the data.
35+
36+
channel.clear queueName, ->
37+
console.log 'cleared'
38+
doImportantStuff()
39+
40+
1. Optionally, push data to your queue
41+
42+
channel.push queueName, myData
43+
44+
1. Optionally, pop data off your queue
45+
46+
channel.pop queueName, (myData) ->
47+
console.log 'data = ' + myData
48+
49+
or, alternatively, pop off any of multiple queues
50+
51+
channel.popAny queueName1, queueName2, (myData) ->
52+
console.log 'data = ' + myData
53+
54+
Once popping data from a queue, avoid pushing data to the same queue from the same connection, since
55+
a hang could result. This appears to be a Redis limitation when using blocking reads.
56+
57+
1. When done, quit the Channel instance
58+
59+
channel.disconnect()
60+
61+
or, alternatively, if consuming data from the queue, end the connection
62+
63+
channel.end()
64+
65+
or, if there may be a number of redis commands queued,
66+
67+
channel.shutdownSoon()
68+
69+
###WorkQueueMgr Coffeescript Usage Example
70+
71+
1. Ensure you have a Redis server installed and running. For example, once installed, you can run it locally by
72+
73+
redis-server &
74+
75+
1. Require `node-redis-queue` WorkQueueMgr
76+
77+
WorkQueueMgr = require('node-redis-queue').WorkQueueMgr
78+
79+
1. Create a WorkQueueMgr instance and connect to Redis
80+
81+
mgr = new WorkQueueMgr()
82+
mgr.connect ->
83+
console.log 'ready'
84+
myMainLogic()
85+
86+
Alternatively, you can provide an existing Redis connection (i.e., a redis client instance)
87+
88+
mgr.attach redisConn
89+
90+
1. Optionally, handle error events
91+
92+
mgr.on 'error', (error) ->
93+
console.log 'Stopping due to: ' + error
94+
process.exit()
95+
96+
1. Optionally, handle lost connection events
97+
98+
mgr.on 'end', ->
99+
console.log 'Connection lost'
100+
101+
1. Create a work queue instance
102+
103+
queue = mgr.createQueue queueName
104+
105+
1. Optionally, clear previous data from the queue, providing a callback
106+
to handle the data.
107+
108+
queue.clear ->
109+
console.log 'cleared'
110+
doImportantStuff()
111+
112+
1. Optionally, send data to your queue
113+
114+
queue.send myData
115+
116+
1. Optionally, consume data from your queue and call ack when ready to consume another data item
117+
118+
queue.consume (myData, ack) ->
119+
console.log 'data = ' + myData
120+
...
121+
ack()
122+
123+
or, alternatively,
124+
125+
queue.consume (myData, ack) ->
126+
console.log 'data = ' + myData
127+
...
128+
ack()
129+
, arity
130+
131+
where arity is an integer indicating the number of async callbacks to schedule in parallel. See demo 04 for example usage.
132+
133+
If multiple queues are being consumed, they are consumed with highest priority given to the queues consumed first
134+
(i.e., in the order in which the consume statements are executed).
135+
136+
Note that ack(true) may be used to indicate that no further data is expected from the given work queue.
137+
This is useful, for example, in testing, when a clean exit from a test case is desired.
138+
139+
Once consuming from a queue, avoid sending data to the same queue from the same connection
140+
(i.e., the same mgr instance), since a hang could result. This appears to be a Redis limitation when using
141+
blocking reads. You can test `mgr.channel.outstanding` for zero to determine if it is OK to send on the same connection.
142+
143+
1. Optionally, destroy a work queue if it no longer is needed. Assign null to the queue variable to free up memory.
144+
145+
queue.destroy()
146+
queue = null
147+
148+
1. When done, quit the WorkQueueMgr instance
149+
150+
mgr.disconnect()
151+
152+
or, alternatively, if consuming data from the queue, end the connection
153+
154+
mgr.end()
155+
156+
or, if there may be a number of redis commands queued,
157+
158+
mgr.shutdownSoon()
159+

DEVELOPER_INFO.md

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
##Running the test suite
2+
3+
Use either `grunt test` or `npm test` to run the suite of tests using Mocha. The test cases reside in the `test` directory.
4+
5+
##Running grunt for development tasks
6+
7+
`grunt` runs coffeelint and then coffee.
8+
9+
`grunt coffeelint` runs coffeelint on all the .coffee source code in the src directory.
10+
11+
`grunt coffee` runs coffee on all the .coffee source code in the src directory, converting it to .js code in the
12+
corresponding lib directory.
13+
14+
`grunt jshint` runs jshint on all the .js code except one in the demo/lib/helpers directory. Note that jshint may
15+
have a lot of complaints about the generated .js code, but is useful to spot potential problems.
16+
17+
`grunt clean` runs a script that removes vim backup files (i.e., files ending with '~' and .js files in the test directory).
18+
19+
`grunt test` runs the suite of tests using Mocha. It looks for .coffee files in the test directory.
20+
21+
`grunt bump` bumps the patch number up in the package.json file.
22+
23+
`grunt git-tag` commits the latest staged code changes and tags the code with the version obtained from the package.json file.
24+
25+
`grunt release` runs coffee on all the .coffee source code in the src directory, converting it to .js code, and
26+
then runs the git-tag task to commit the latest staged code changes and tag the code with the version obtained from the
27+
package.json file.
28+
29+
`grunt compile-test` runs coffee on the test .coffee code. This is only for debugging of test cases when you need to see the generated javascript code.
30+

0 commit comments

Comments
 (0)