Skip to content
This repository has been archived by the owner on Mar 22, 2024. It is now read-only.

Commit

Permalink
Merge pull request #437 from Financial-Times/matth/scale-inhibit-option
Browse files Browse the repository at this point in the history
Add inhibit option to scale task and use for ship task
  • Loading branch information
i-like-robots authored Dec 13, 2016
2 parents 4d2582f + 790107a commit e92abdf
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 9 deletions.
23 changes: 18 additions & 5 deletions tasks/scale.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,20 @@ function task (opts) {
}

const processProfiles = Object.keys(processInfo).map(process => {
return process + '=' + (opts.minimal ? 1 : processInfo[process].scale)
+ ':' + (opts.minimal ? 'standard-1X' : processInfo[process].size);
});
let scale = processInfo[process].scale;
let size = processInfo[process].size;

if (opts.minimal) {
scale = 1;
size = 'standard-1X';
}

if (opts.inhibit) {
scale = 0;
}

return `${process}=${scale}:${size}`;
});

return shellpromise('heroku ps:scale ' + processProfiles.join(' ') + ' --app ' + target, { verbose: true });

Expand All @@ -57,12 +68,14 @@ module.exports = function (program, utils) {
program
.command('scale [source] [target]')
.description('downloads process information from next-service-registry and scales/sizes the application servers')
.option('-m, --minimal', 'scales each dyno to a single instance (useful for provisioning a test app)')
.option('-m, --minimal', 'scales each dyno to a single instance')
.option('-i, --inhibit', 'scales each dyno down to 0')
.action(function (source, target, options) {
task({
source: source,
target: target,
minimal: options.minimal
minimal: options.minimal,
inhibit: options.inhibit
}).catch(utils.exit);
});
};
Expand Down
6 changes: 4 additions & 2 deletions tasks/ship.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ function task (opts) {
}

log.info('Scale staging app to 1 dyno');
yield scale({target:apps.staging, scale:'web=1'}).catch(function (){
yield scale({ source: appName, target: apps.staging, minimal: true }).catch(function (){
log.info('Failed to scale up staging app - is this the first run?')
});

Expand Down Expand Up @@ -86,7 +86,9 @@ function task (opts) {
}

log.info('scale staging app back to 0');
yield scale({target:apps.staging, scale:'web=0'});
yield scale({ source: appName, target: apps.staging, inhibit: true }).catch(() => {
log.warn('Failed to scale down staging app');
});

log.success('Shipped!');
log.art.ship(appName);
Expand Down
8 changes: 6 additions & 2 deletions test/ship.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,12 @@ describe('tasks/ship', function (){

it('Should scale to staging app up to 1 web dyno before deploying', function (){
let pipelineName = 'test';
let appName = 'sample-app';

return co(function* (){
yield ship({pipeline:pipelineName});

sinon.assert.calledWith(mockScale.task, {target:mockApps.staging, scale:'web=1'});
sinon.assert.calledWith(mockScale.task, {source:appName, target:mockApps.staging, minimal:true});
});
});

Expand Down Expand Up @@ -98,10 +100,12 @@ describe('tasks/ship', function (){

it('Should scale the staging app down to 0 when complete', function (){
let pipelineName = 'test';
let appName = 'sample-app';

return co(function* (){
yield ship({pipeline:pipelineName});

sinon.assert.calledWith(mockScale.task, {target:mockApps.staging, scale:'web=0'});
sinon.assert.calledWith(mockScale.task, {source:appName, target:mockApps.staging, inhibit:true});
});
});

Expand Down

0 comments on commit e92abdf

Please sign in to comment.