Skip to content

Commit

Permalink
added the opposition party worker. and the subtract job
Browse files Browse the repository at this point in the history
  • Loading branch information
liangzan committed May 6, 2011
1 parent 508e9ef commit 1c4dbe7
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 1 deletion.
6 changes: 6 additions & 0 deletions lib/jobs.js
Expand Up @@ -25,3 +25,9 @@ ResqueJobs.prototype.addHDBValue = function(value, callback) {
callback(null);
};

ResqueJobs.prototype.subtractHDBValue = function(value, callback) {
this.log.method_info("ResqueJobs.subtractHDBValue", {value: value});
client.decrby(this.hdbFlatPrice, value, redis.print);
callback(null);
};

37 changes: 37 additions & 0 deletions scripts/opposition_party.js
@@ -0,0 +1,37 @@
var fs = require('fs'),
sys = require('sys'),
path = require('path'),
config = require('../config/initialize'),
Logger = require('../lib/log').Logger,
ResqueJobs = require('../lib/jobs').ResqueJobs,
resque = require('../node_modules/coffee-resque').connect(),
_ = require('../node_modules/underscore');

var log = new Logger();

/*
* resque takes the entire function out and runs it
* functions need to be self-contained
*/
var workerJobs = {
addHDBValue: function(value, callback) {
var jobs = new ResqueJobs();
jobs.addHDBValue(value, callback);
},

subtractHDBValue: function(value, callback) {
var jobs = new ResqueJobs();
jobs.subtractHDBValue(value, callback);
}
};

try {
var opposition = require('coffee-resque')
.connect({timeout: 500})
.worker('high', workerJobs);

opposition.start();
} catch (err) {
opposition.end();
opposition.start();
}
6 changes: 6 additions & 0 deletions scripts/pap_minister.js
Expand Up @@ -17,7 +17,13 @@ var workerJobs = {
addHDBValue: function(value, callback) {
var jobs = new ResqueJobs();
jobs.addHDBValue(value, callback);
},

subtractHDBValue: function(value, callback) {
var jobs = new ResqueJobs();
jobs.subtractHDBValue(value, callback);
}

};

try {
Expand Down
4 changes: 3 additions & 1 deletion scripts/queue_jobs.js
Expand Up @@ -13,9 +13,11 @@ var hdbFlatPrice = "hdb_flat";

setInterval(
function() {
var currHDBValue = client.get(hdbFlatPrice);
var increase = 5000;
resque.enqueue('high', 'addHDBValue', [increase]);

var decrease = 1000;
resque.enqueue('high', 'subtractHDBValue', [decrease]);
}, 1000);


0 comments on commit 1c4dbe7

Please sign in to comment.