Skip to content

Commit

Permalink
bit of optimisation - ie do not keep parsing the done files. Need to …
Browse files Browse the repository at this point in the history
…automatically remove these over time or only re-parse after 1 hour of last check
  • Loading branch information
remy committed Feb 10, 2012
1 parent 2aa4066 commit 463f9f3
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 14 deletions.
37 changes: 25 additions & 12 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions prefix.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -317,7 +317,7 @@ function retrofit(css, lint) {
}

function urlAsPath(url) {
return url.toLowerCase().replace(/.*?:\/\//, '').replace(/\//g, '_');
return url.toLowerCase().replace(/.*?:\/\//, '').replace(/\?/, '-').replace(/\//g, '_');
}


Expand Down

0 comments on commit 463f9f3

Please sign in to comment.