Skip to content
Browse files

removed Que.Models, moved all methods to Que class

  • Loading branch information...
1 parent b53de62 commit a9ca3a757f6d9b57d19cbab6080554dbd317c1f8 @vdemedes committed Jul 2, 2012
Showing with 17 additions and 26 deletions.
  1. +1 −1 Readme.md
  2. +8 −9 lib/que.coffee
  3. +6 −14 lib/que.js
  4. +1 −1 package.json
  5. +1 −1 test/que.test.coffee
View
2 Readme.md
@@ -60,7 +60,7 @@ class EchoReverseWorker extends Que.Model
result = @params.message.split('').reverse().join('')
callback false, echo: result
-EchoReverseWorker = Que.Models.setup EchoReverseWorker # this is required, notice **Models** here, not just **Model**
+EchoReverseWorker = Que.setup EchoReverseWorker # this is required, notice **Models** here, not just **Model**
```
### Making own drivers
View
17 lib/que.coffee
@@ -27,20 +27,17 @@ class Que # namespace
driver.disconnect -> do nextDriver
, ->
do callback if callback
-
-Que.registerDriver 'gearman', require('./drivers/gearman')
-
-class Que.Models
- @workers: {}
+ @workers: {}
+
@define: (params) -> # for non-coffee folks
worker = clone Que.Model
for param of params
worker::[param] = params[param] if params.hasOwnProperty param
-
+
@setup worker
-
-
+
+
@setup: (worker) ->
worker.job = worker::job
worker.driver = Que.drivers[worker::driver]
@@ -51,10 +48,12 @@ class Que.Models
processor.response = response
processor.finished.call processor err if processor.finished
job.end JSON.stringify response
-
+
@workers[worker::job] = worker
worker
+Que.registerDriver 'gearman', require('./drivers/gearman')
+
class Que.Model
constructor: ->
View
20 lib/que.js
@@ -57,19 +57,9 @@ Que = (function() {
});
};
- return Que;
-
-})();
-
-Que.registerDriver('gearman', require('./drivers/gearman'));
-
-Que.Models = (function() {
+ Que.workers = {};
- function Models() {}
-
- Models.workers = {};
-
- Models.define = function(params) {
+ Que.define = function(params) {
var param, worker;
worker = clone(Que.Model);
for (param in params) {
@@ -80,7 +70,7 @@ Que.Models = (function() {
return this.setup(worker);
};
- Models.setup = function(worker) {
+ Que.setup = function(worker) {
worker.job = worker.prototype.job;
worker.driver = Que.drivers[worker.prototype.driver];
worker.driver.register(worker.prototype.job, function(params, job) {
@@ -99,10 +89,12 @@ Que.Models = (function() {
return worker;
};
- return Models;
+ return Que;
})();
+Que.registerDriver('gearman', require('./drivers/gearman'));
+
Que.Model = (function() {
function Model() {}
View
2 package.json
@@ -1,6 +1,6 @@
{
"name": "que",
- "version": "0.1.1",
+ "version": "0.1.2",
"description": "Interface to many worker queue backends.",
"author": "Vadim Demedes <sbioko@gmail.com>",
"main": "./index.js",
View
2 test/que.test.coffee
@@ -15,7 +15,7 @@ describe 'Que', ->
process: (callback) ->
callback false, echo: @params.message.split('').reverse().join('')
- EchoReverseWorker = Que.Models.setup EchoReverseWorker
+ EchoReverseWorker = Que.setup EchoReverseWorker
EchoReverseWorker.submit message: '2pac', (err, response) ->
response.echo.should.equal 'cap2'

0 comments on commit a9ca3a7

Please sign in to comment.
Something went wrong with that request. Please try again.