Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

added the opposition party worker. and the subtract job

  • Loading branch information...
commit 1c4dbe7fde9ffcc8689e0e0c4c9eaddfbbbb0820 1 parent 508e9ef
Wong Liang Zan authored May 06, 2011
6  lib/jobs.js
@@ -25,3 +25,9 @@ ResqueJobs.prototype.addHDBValue = function(value, callback) {
25 25
     callback(null);
26 26
 };
27 27
 
  28
+ResqueJobs.prototype.subtractHDBValue = function(value, callback) {
  29
+    this.log.method_info("ResqueJobs.subtractHDBValue", {value: value});
  30
+    client.decrby(this.hdbFlatPrice, value, redis.print);
  31
+    callback(null);
  32
+};
  33
+
37  scripts/opposition_party.js
... ...
@@ -0,0 +1,37 @@
  1
+var fs = require('fs'),
  2
+    sys = require('sys'),
  3
+    path = require('path'),
  4
+    config = require('../config/initialize'),
  5
+    Logger = require('../lib/log').Logger,
  6
+    ResqueJobs = require('../lib/jobs').ResqueJobs,
  7
+    resque = require('../node_modules/coffee-resque').connect(),
  8
+    _ = require('../node_modules/underscore');
  9
+
  10
+var log = new Logger();
  11
+
  12
+/*
  13
+ * resque takes the entire function out and runs it
  14
+ * functions need to be self-contained
  15
+ */
  16
+var workerJobs = {
  17
+    addHDBValue: function(value, callback) {
  18
+	var jobs = new ResqueJobs();
  19
+	jobs.addHDBValue(value, callback);      
  20
+    },
  21
+
  22
+    subtractHDBValue: function(value, callback) {
  23
+	var jobs = new ResqueJobs();
  24
+	jobs.subtractHDBValue(value, callback);      
  25
+    }
  26
+};
  27
+
  28
+try {
  29
+    var opposition = require('coffee-resque')
  30
+	.connect({timeout: 500})
  31
+	.worker('high', workerJobs);
  32
+
  33
+    opposition.start();
  34
+} catch (err) {
  35
+    opposition.end();
  36
+    opposition.start();
  37
+}
6  scripts/pap_minister.js
@@ -17,7 +17,13 @@ var workerJobs = {
17 17
     addHDBValue: function(value, callback) {
18 18
 	var jobs = new ResqueJobs();
19 19
 	jobs.addHDBValue(value, callback);      
  20
+    },
  21
+
  22
+    subtractHDBValue: function(value, callback) {
  23
+	var jobs = new ResqueJobs();
  24
+	jobs.subtractHDBValue(value, callback);      
20 25
     }
  26
+
21 27
 };
22 28
 
23 29
 try {
4  scripts/queue_jobs.js
@@ -13,9 +13,11 @@ var hdbFlatPrice = "hdb_flat";
13 13
 
14 14
 setInterval(
15 15
     function() {
16  
-	var currHDBValue = client.get(hdbFlatPrice);
17 16
 	var increase = 5000;
18 17
 	resque.enqueue('high', 'addHDBValue', [increase]);
  18
+
  19
+	var decrease = 1000;
  20
+	resque.enqueue('high', 'subtractHDBValue', [decrease]);
19 21
     }, 1000);
20 22
 
21 23
 

0 notes on commit 1c4dbe7

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