-
Notifications
You must be signed in to change notification settings - Fork 0
/
preprocess.js
47 lines (42 loc) · 1.37 KB
/
preprocess.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
/**
* @fileoverview Processes all queued up requests at launch time.
*/
var mongoose = require('mongoose');
var db = mongoose.connect('mongodb://localhost/soapq');
var requests = require('./models/models.js').requests;
var SoapQ = require('./lib/soapq.js').SoapQ;
/**
* Process all unhandled requests at server launch time.
*/
exports.process = function() {
console.log('Processing queued requests.');
var Model = mongoose.model('requests', requests);
Model.find({}, function(err, docs) {
if (err) {
console.log(err);
return;
}
for (x in docs) {
var doc = docs[x];
var soapq = new SoapQ(doc.key, doc.payload, doc.respondURL);
// Make the SOAP request.
soapq.request();
// After all requests have been made, respond to the callback.
soapq.on('requestedRequests', function requestedRequests(message) {
console.log(message);
soapq.respond();
});
// If there was an error during processing log it and set the request
// status to false.
soapq.on('requestErrors', function requestErrors(message) {
console.log(message);
soapq.requestStatus = false;
soapq.respond();
});
// After the request was processed, remove it from the database.
soapq.on('processedRequest', function processedRequest(message) {
soapq.remove();
});
}
});
};