Skip to content
Browse files

bit of optimisation - ie do not keep parsing the done files. Need to …

…automatically remove these over time or only re-parse after 1 hour of last check
  • Loading branch information...
1 parent 2aa4066 commit 463f9f3610be2dfd57e9af4aa2eaed401a30ab46 @remy committed Feb 10, 2012
Showing with 27 additions and 14 deletions.
  1. +25 −12 app.js
  2. +2 −2 prefix.js
View
37 app.js
@@ -22,6 +22,9 @@ path.exists(__dirname + '/public/jobs', function (exists) {
}
});
+function urlAsPath(url) {
+ return url.toLowerCase().replace(/.*?:\/\//, '').replace(/\//g, '_');
+}
var app = module.exports = express.createServer();
@@ -71,20 +74,30 @@ app.get('/check.json', function (req, res) {
prefix.send({ type: 'start', url: req.query.url, dirtyExit: true });
});
-app.get(/\/(.*)?/, function (req, res) {
- console.log(req.headers);
- var prefix = cp.fork(__dirname + '/prefix.js');
-
- prefix.on('message', function(event) {
- console.log(event);
- if (event.type == 'end') {
- res.send('<a href="/jobs/' + event.job + '.zip">' + event.job + '.zip</a>');
+app.get(/\/check\/(.*)?/, function (req, res) {
+ var job = urlAsPath(req.params[0]);
+ path.exists(__dirname + '/public/jobs/' + job + '.zip', function (exists) {
+ var ready = function () {
+ res.send('<a href="/jobs/' + job + '.zip">' + job + '.zip</a>');
+ };
+
+ if (!exists) {
+ var prefix = cp.fork(__dirname + '/prefix.js');
+
+ prefix.on('message', function(event) {
+ // console.log(event);
+ if (event.type == 'end') {
+ ready();
+ }
+ // res.writeHead(200, { 'content-type': 'text/css' });
+ // res.end('');
+ });
+
+ prefix.send({ type: 'start', url: req.params[0] });
+ } else {
+ ready();
}
- // res.writeHead(200, { 'content-type': 'text/css' });
- // res.end('');
});
-
- prefix.send({ type: 'start', url: req.params[0] });
});
app.listen(process.env.PORT || 8000);
View
4 prefix.js
@@ -44,7 +44,7 @@ Prefix.prototype.dirty = false;
Prefix.prototype.end = function () {
var self = this;
- var child = exec('zip ' + __dirname + '/public/jobs/' + self.job + '.zip *.css', { cwd: self.dir }, function (error, stdout, stderr) {
+ var child = exec('zip ' + __dirname + '/public/jobs/' + self.job + '.zip *.*', { cwd: self.dir }, function (error, stdout, stderr) {
if (error !== null) {
console.log('exec error: ' + error);
}
@@ -317,7 +317,7 @@ function retrofit(css, lint) {
}
function urlAsPath(url) {
- return url.toLowerCase().replace(/.*?:\/\//, '').replace(/\//g, '_');
+ return url.toLowerCase().replace(/.*?:\/\//, '').replace(/\?/, '-').replace(/\//g, '_');
}

0 comments on commit 463f9f3

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