Skip to content
Browse files

changed Que.Worker to Que.Model

  • Loading branch information...
1 parent ab240a1 commit b53de626b9df7f72f17d2c4b1a8b4903ce59ba1a @vdemedes committed
Showing with 19 additions and 19 deletions.
  1. +2 −2 Readme.md
  2. +3 −3 lib/que.coffee
  3. +11 −11 lib/que.js
  4. +1 −1 package.json
  5. +2 −2 test/que.test.coffee
View
4 Readme.md
@@ -52,7 +52,7 @@ EchoReverseWorker.submit({ message: '2pac' }, function(err, response){ // second
You can define workers using CoffeeScript native class system:
```coffee-script
-class EchoReverseWorker extends Que.Worker
+class EchoReverseWorker extends Que.Model
job: 'echoReverse'
driver: 'gearman'
@@ -60,7 +60,7 @@ class EchoReverseWorker extends Que.Worker
result = @params.message.split('').reverse().join('')
callback false, echo: result
-EchoReverseWorker = Que.Workers.setup EchoReverseWorker # this is required
+EchoReverseWorker = Que.Models.setup EchoReverseWorker # this is required, notice **Models** here, not just **Model**
```
### Making own drivers
View
6 lib/que.coffee
@@ -30,11 +30,11 @@ class Que # namespace
Que.registerDriver 'gearman', require('./drivers/gearman')
-class Que.Workers
+class Que.Models
@workers: {}
@define: (params) -> # for non-coffee folks
- worker = clone Que.Worker
+ worker = clone Que.Model
for param of params
worker::[param] = params[param] if params.hasOwnProperty param
@@ -55,7 +55,7 @@ class Que.Workers
@workers[worker::job] = worker
worker
-class Que.Worker
+class Que.Model
constructor: ->
@submit: (params, callback) ->
View
22 lib/que.js
@@ -63,15 +63,15 @@ Que = (function() {
Que.registerDriver('gearman', require('./drivers/gearman'));
-Que.Workers = (function() {
+Que.Models = (function() {
- function Workers() {}
+ function Models() {}
- Workers.workers = {};
+ Models.workers = {};
- Workers.define = function(params) {
+ Models.define = function(params) {
var param, worker;
- worker = clone(Que.Worker);
+ worker = clone(Que.Model);
for (param in params) {
if (params.hasOwnProperty(param)) {
worker.prototype[param] = params[param];
@@ -80,7 +80,7 @@ Que.Workers = (function() {
return this.setup(worker);
};
- Workers.setup = function(worker) {
+ Models.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,15 +99,15 @@ Que.Workers = (function() {
return worker;
};
- return Workers;
+ return Models;
})();
-Que.Worker = (function() {
+Que.Model = (function() {
- function Worker() {}
+ function Model() {}
- Worker.submit = function(params, callback) {
+ Model.submit = function(params, callback) {
var data, worker;
worker = this.driver.submit(this.job, JSON.stringify(params));
data = void 0;
@@ -121,7 +121,7 @@ Que.Worker = (function() {
});
};
- return Worker;
+ return Model;
})();
View
2 package.json
@@ -1,6 +1,6 @@
{
"name": "que",
- "version": "0.1.0",
+ "version": "0.1.1",
"description": "Interface to many worker queue backends.",
"author": "Vadim Demedes <sbioko@gmail.com>",
"main": "./index.js",
View
4 test/que.test.coffee
@@ -8,14 +8,14 @@ describe 'Que', ->
describe 'Drivers', ->
describe 'Gearman', ->
it 'should process data', (done) ->
- class EchoReverseWorker extends Que.Worker
+ class EchoReverseWorker extends Que.Model
driver: 'gearman'
job: 'echoReverse'
process: (callback) ->
callback false, echo: @params.message.split('').reverse().join('')
- EchoReverseWorker = Que.Workers.setup EchoReverseWorker
+ EchoReverseWorker = Que.Models.setup EchoReverseWorker
EchoReverseWorker.submit message: '2pac', (err, response) ->
response.echo.should.equal 'cap2'

0 comments on commit b53de62

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