MCPcopy
hub / github.com/Unitech/pm2 / scale

Method scale

lib/API.js:1795–1854  ·  view source on GitHub ↗

* Scale up/down a process * @method scale

(app_name, number, cb)

Source from the content-addressed store, hash-verified

1793 * @method scale
1794 */
1795 scale (app_name, number, cb) {
1796 var that = this;
1797
1798 function addProcs(proc, value, cb) {
1799 (function ex(proc, number) {
1800 if (number-- === 0) return cb();
1801 Common.printOut(conf.PREFIX_MSG + 'Scaling up application');
1802 that.Client.executeRemote('duplicateProcessId', proc.pm2_env.pm_id, ex.bind(this, proc, number));
1803 })(proc, number);
1804 }
1805
1806 function rmProcs(procs, value, cb) {
1807 var i = 0;
1808
1809 (function ex(procs, number) {
1810 if (number++ === 0) return cb();
1811 that._operate('deleteProcessId', procs[i++].pm2_env.pm_id, ex.bind(this, procs, number));
1812 })(procs, number);
1813 }
1814
1815 function end() {
1816 return cb ? cb(null, {success:true}) : that.speedList();
1817 }
1818
1819 this.Client.getProcessByName(app_name, function(err, procs) {
1820 if (err) {
1821 Common.printError(err);
1822 return cb ? cb(Common.retErr(err)) : that.exitCli(conf.ERROR_EXIT);
1823 }
1824
1825 if (!procs || procs.length === 0) {
1826 Common.printError(conf.PREFIX_MSG_ERR + 'Application %s not found', app_name);
1827 return cb ? cb(new Error('App not found')) : that.exitCli(conf.ERROR_EXIT);
1828 }
1829
1830 var proc_number = procs.length;
1831
1832 if (typeof(number) === 'string' && number.indexOf('+') >= 0) {
1833 number = parseInt(number, 10);
1834 return addProcs(procs[0], number, end);
1835 }
1836 else if (typeof(number) === 'string' && number.indexOf('-') >= 0) {
1837 number = parseInt(number, 10);
1838 return rmProcs(procs[0], number, end);
1839 }
1840 else {
1841 number = parseInt(number, 10);
1842 number = number - proc_number;
1843
1844 if (number < 0)
1845 return rmProcs(procs, number, end);
1846 else if (number > 0)
1847 return addProcs(procs[0], number, end);
1848 else {
1849 Common.printError(conf.PREFIX_MSG_ERR + 'Nothing to do');
1850 return cb ? cb(new Error('Same process number')) : that.exitCli(conf.ERROR_EXIT);
1851 }
1852 }

Callers 3

CLI.jsFile · 0.45
cluster.mocha.jsFile · 0.45
id.mocha.jsFile · 0.45

Calls 6

cbFunction · 0.85
addProcsFunction · 0.85
rmProcsFunction · 0.85
getProcessByNameMethod · 0.80
exitCliMethod · 0.80
indexOfMethod · 0.80

Tested by

no test coverage detected