Created
October 18, 2014 00:35
-
-
Save arlolra/8aaa919960664d837590 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require("prfun"); | |
var request = Promise.promisify(require('request'), true); | |
var HOURS = 24 * 60 * 60 * 1000; | |
var opts = { | |
method: "post", | |
url: "https://logstash.wikimedia.org/logstash-2014.10.17/_search" | |
auth: { | |
user: "", | |
pass: "" | |
} | |
}; | |
function query(q, size) { | |
return { | |
"query": { | |
"filtered": { | |
"query": { "bool": { | |
"should": [ { "query_string": { "query": q } } ] | |
} }, | |
"filter": { "bool": { "must": [ | |
{ "range": { "@timestamp": { "from": Date.now() - HOURS, "to": "now" } } }, | |
{ "terms": { "_type": [ "OfflineContentGenerator" ] } } | |
] } } | |
} | |
}, | |
"size": size | |
} | |
} | |
request(Object.assign({ | |
json: query("message: \"Got new job\"", 100) | |
}, opts)).spread(function(res, body) { | |
return body.hits.hits; | |
}).filter(function(k) { | |
return request(Object.assign({ | |
json: query("job.id: " + k._source.job.id, 2000) | |
}, opts)).spread(function(res, body) { | |
return !body.hits.hits.some(function(h) { | |
return /^Render completed successfully!$/.test(h._source.message); | |
}); | |
}).catch(function(err) { | |
return false; | |
}); | |
}).then(function(res) { | |
res.forEach(function(b) { | |
console.log(b._source.job.id) | |
}) | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment