diff --git a/lib/job.js b/lib/job.js index a709e3f8..6282c702 100644 --- a/lib/job.js +++ b/lib/job.js @@ -1155,53 +1155,59 @@ module.exports = Class.create({ // get read stream and prepare to compress it var stream = fs.createReadStream( job.log_file ); var gzip = zlib.createGzip( self.server.config.get('gzip_opts') || {} ); - stream.pipe( gzip ); + var temp_file = job.log_file + '.gz'; + var temp_stream = fs.createWriteStream( temp_file ); - self.storage.putStream( path, gzip, function(err) { - if (err) { - self.logError('storage', "Failed to store job log: " + path + ": " + err); - if (callback) callback(err); - return; - } - - self.logDebug(9, "Job log stored successfully: " + path); + stream.pipe( gzip ).pipe( temp_stream ).on("finish", function() { + var new_stream = fs.createReadStream( temp_file ); - // delete or move local log file - if (self.server.config.get('copy_job_logs_to')) { - var dargs = Tools.getDateArgs( Tools.timeNow() ); - var dest_path = self.server.config.get('copy_job_logs_to').replace(/\/$/, '') + '/'; - if (job.event_title) dest_path += job.event_title.replace(/\W+/g, '') + '.'; - dest_path += job.id + '.' + (dargs.yyyy_mm_dd + '-' + dargs.hh_mi_ss).replace(/\W+/g, '-'); - dest_path += '.log'; + self.storage.putStream( path, new_stream, function(err) { + fs.unlink( temp_file, function(err) {;} ); + if (err) { + self.logError('storage', "Failed to store job log: " + path + ": " + err); + if (callback) callback(err); + return; + } - self.logDebug(9, "Moving local file: " + job.log_file + " to: " + dest_path); + self.logDebug(9, "Job log stored successfully: " + path); - self.logger.rotate( job.log_file, dest_path, function(err) { - if (err) { - self.logError('file', "Failed to move local job log file: " + job.log_file + ": " + err); - fs.unlink( job.log_file, function(err) {;} ); - } - else { - self.logDebug(9, "Successfully moved local job log file: " + job.log_file + ": " + dest_path); - } - if (callback) callback(); - } ); - } - else { - self.logDebug(9, "Deleting local file: " + job.log_file); - fs.unlink( job.log_file, function(err) { - // all done - if (err) { - self.logError('file', "Failed to delete local job log file: " + job.log_file + ": " + err); - } - else { - self.logDebug(9, "Successfully deleted local job log file: " + job.log_file); - } - if (callback) callback(); + // delete or move local log file + if (self.server.config.get('copy_job_logs_to')) { + var dargs = Tools.getDateArgs( Tools.timeNow() ); + var dest_path = self.server.config.get('copy_job_logs_to').replace(/\/$/, '') + '/'; + if (job.event_title) dest_path += job.event_title.replace(/\W+/g, '') + '.'; + dest_path += job.id + '.' + (dargs.yyyy_mm_dd + '-' + dargs.hh_mi_ss).replace(/\W+/g, '-'); + dest_path += '.log'; - } ); // fs.unlink - } // delete - } ); // storage put + self.logDebug(9, "Moving local file: " + job.log_file + " to: " + dest_path); + + self.logger.rotate( job.log_file, dest_path, function(err) { + if (err) { + self.logError('file', "Failed to move local job log file: " + job.log_file + ": " + err); + fs.unlink( job.log_file, function(err) {;} ); + } + else { + self.logDebug(9, "Successfully moved local job log file: " + job.log_file + ": " + dest_path); + } + if (callback) callback(); + } ); + } + else { + self.logDebug(9, "Deleting local file: " + job.log_file); + fs.unlink( job.log_file, function(err) { + // all done + if (err) { + self.logError('file', "Failed to delete local job log file: " + job.log_file + ": " + err); + } + else { + self.logDebug(9, "Successfully deleted local job log file: " + job.log_file); + } + if (callback) callback(); + + } ); // fs.unlink + } // delete + } ); // storage put + }); // stream pipe } ); // read file } // master else { diff --git a/package.json b/package.json index bbd8cc99..72e2d80e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "Cronicle", - "version": "0.9.13", + "version": "0.9.14", "description": "A simple, distributed task scheduler and runner with a web based UI.", "author": "Joseph Huckaby ", "homepage": "https://github.com/jhuckaby/Cronicle",