download.on('finish', function(){ pt.log('[thurgood] code successfully downloaded.', job.id); logger.info('[job-'+job.id+'] code successfully downloaded.'); try { var zip = new AdmZip(dir + '/archive.zip'); zip.extractAllTo(dir, true); pt.log('[thurgood] code successfully unzipped.', job.id); logger.info('[job-'+job.id+'] code successfully unzipped.'); // delete the archive file so it doesn't get pushed fse.removeSync(dir + "/archive.zip"); /* See if the code is from github and them move * the contents up a folder. When the zip is downloaded * from github it is buried inside a folder named after * the branch. So the file will be in something like * '/tmp/job1/push-test-master' instead of '/tmp/job1'. * We need to move everything up into the tmp dir for * for the project so it is a consistent structure. */ if (job.codeUrl.split('/')[2].indexOf('github.com') != -1) { githubRootFolder(dir) .then(function(githubDir){ fse.copySync(githubDir, dir, {clobber: true}); fse.removeSync(githubDir); fse.removeSync(path.resolve(dir, '__MACOSX')); resolve(job); }) } else { // try and delete a '__MACOSX' if it exists fse.removeSync(path.resolve(dir, '__MACOSX')); resolve(job); } } catch (err) { reject(err); } })
environment.updateAttributes(attributes, function(err, environment){ if (err) reject(err); if (!err) { logger.info('[job-'+id+'] environment rolled back due to error'); resolve(id); } });
Job.findById(id, function(err, job){ if (!err && job) { pt.log('[' +sender+ '] ' + message, job.id); logger.info('[job-'+job.id+']['+sender+'] ' + message); var msg = { success: true, message: 'Message sent to logger' } cb(null, msg); } else { logger.error('[job-'+id+']['+sender+'] could not find job for message!!'); var msg = { success: false, message: 'Job not found for message' } cb(null, msg); } });
job.updateAttributes(attributes, function(err, job){ if (err) reject(err); if (!err) { logger.info('[job-'+id+'] job rolled back due to error'); app.models.Environment.findOne({where: {jobId: id}}, function(err, environment){ if (err) reject(err); if (environment && !err) { var attributes = { jobId: null, status: 'available', updatedAt: new Date() } environment.updateAttributes(attributes, function(err, environment){ if (err) reject(err); if (!err) { logger.info('[job-'+id+'] environment rolled back due to error'); resolve(id); } }); } }); } });
.then(function(job) { pt.log('[thurgood] job marked as complete.', id); logger.info('[job-'+job.id+'] marked as complete.'); cb(null, job); }).catch(function(err) {