-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpom.js
79 lines (65 loc) · 2.1 KB
/
pom.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
// Generated by CoffeeScript 1.10.0
(function() {
var Forward, _, async, bs, config, forwarders,
bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };
config = require('./config');
async = require('async');
_ = require('lodash');
bs = require('nodestalker');
console.log(config.get('rules'));
Forward = (function() {
function Forward(rule1) {
var ref;
this.rule = rule1;
this.run = bind(this.run, this);
ref = this.parseRule(this.rule), this.from = ref[0], this.to = ref[1];
}
Forward.prototype.parseRule = function(rule) {
var from, ref, to;
return ref = _.map(_.map(rule.split('->', 2), _.trim), function(dns) {
var ref, server, tube;
ref = dns.split('/', 2), server = ref[0], tube = ref[1];
return {
client: bs.Client(server),
tube: tube
};
}), from = ref[0], to = ref[1], ref;
};
Forward.prototype.run = function() {
var from_client, from_tube, to_client, to_tube;
from_client = this.from.client;
to_client = this.to.client;
from_tube = this.from.tube;
to_tube = this.to.tube;
return from_client.watch(from_tube).onSuccess(function(data) {
var resJob;
resJob = (function(_this) {
return function() {
return from_client.reserve().onSuccess(function(job) {
console.log("reserved", job);
return to_client.use(to_tube).onSuccess(function(toData) {
return to_client.put(job.data).onSuccess(function(fwdData) {
return console.log("fwd", fwdData);
});
});
});
};
})(this);
return resJob();
});
};
return Forward;
})();
forwarders = [];
_.forEach(config.get('rules'), function(rule) {
var forwarder;
forwarder = new Forward(rule);
return forwarders.push(forwarder);
});
async.parallel(_.map(forwarders, 'run'), function(err, results) {
if (err != null) {
console.error(err);
}
return console.log(results);
});
}).call(this);