Permalink
Browse files

added the opposition party worker. and the subtract job

  • Loading branch information...
1 parent 508e9ef commit 1c4dbe7fde9ffcc8689e0e0c4c9eaddfbbbb0820 @liangzan committed May 6, 2011
Showing with 52 additions and 1 deletion.
  1. +6 −0 lib/jobs.js
  2. +37 −0 scripts/opposition_party.js
  3. +6 −0 scripts/pap_minister.js
  4. +3 −1 scripts/queue_jobs.js
View
@@ -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);
+};
+
@@ -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();
+}
View
@@ -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 {
View
@@ -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.