Skip to content

Commit

Permalink
feature: make "pull", "backward" and "forward" works with id and pid
Browse files Browse the repository at this point in the history
  • Loading branch information
wallet77 committed Feb 21, 2018
1 parent c6d7ace commit 0908e9a
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 16 deletions.
36 changes: 20 additions & 16 deletions lib/API/Version.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ module.exports = function(CLI) {

printOut(cst.PREFIX_MSG + 'Updating repository for process name %s', process_name);

that.Client.getProcessByName(process_name, function(err, processes) {
that.Client.getProcessByNameOrId(process_name, function (err, processes) {

if (processes.length === 0) {
printError('No processes with this name: %s', process_name);
return cb ? cb({msg:'Process not found: '+process_name}) : that.exitCli(cst.ERROR_EXIT);
if (err || processes.length === 0) {
printError('No processes with this name or id : %s', process_name);
return cb ? cb({msg: 'Process not found: ' + process_name}) : that.exitCli(cst.ERROR_EXIT);
}

var proc = processes[0];
Expand Down Expand Up @@ -82,11 +82,11 @@ module.exports = function(CLI) {

printOut(cst.PREFIX_MSG + 'Updating repository for process name %s', process_name);

that.Client.getProcessByName(process_name, function(err, processes) {
that.Client.getProcessByNameOrId(process_name, function (err, processes) {

if (processes.length === 0) {
printError('No processes with this name: %s', process_name);
return cb ? cb({msg:'Process not found: ' + process_name}) : that.exitCli(cst.ERROR_EXIT);
if (err || processes.length === 0) {
printError('No processes with this name or id : %s', process_name);
return cb ? cb({msg: 'Process not found: ' + process_name}) : that.exitCli(cst.ERROR_EXIT);
}

var proc = processes[0];
Expand Down Expand Up @@ -138,14 +138,16 @@ module.exports = function(CLI) {
var that = this;
printOut(cst.PREFIX_MSG + 'Downgrading to previous commit repository for process name %s', process_name);

that.Client.getProcessByName(process_name, function(err, processes) {
that.Client.getProcessByNameOrId(process_name, function (err, processes) {

if (processes.length === 0) {
printError('No processes with this name: %s', process_name);
return cb ? cb({msg:'Process not found: '+process_name}) : that.exitCli(cst.ERROR_EXIT);
if (err || processes.length === 0) {
printError('No processes with this name or id : %s', process_name);
return cb ? cb({msg: 'Process not found: ' + process_name}) : that.exitCli(cst.ERROR_EXIT);
}

var proc = processes[0];
// in case user searched by id/pid
process_name = proc.name;

if (proc.pm2_env.versioning === undefined ||
proc.pm2_env.versioning === null)
Expand Down Expand Up @@ -194,14 +196,16 @@ module.exports = function(CLI) {
var that = this;
printOut(cst.PREFIX_MSG + 'Updating to next commit repository for process name %s', process_name);

that.Client.getProcessByName(process_name, function(err, processes) {
that.Client.getProcessByNameOrId(process_name, function (err, processes) {

if (processes.length === 0) {
printError('No processes with this name: %s', process_name);
return cb ? cb({msg:'Process not found: '+process_name}) : that.exitCli(cst.ERROR_EXIT);
if (err || processes.length === 0) {
printError('No processes with this name or id: %s', process_name);
return cb ? cb({msg: 'Process not found: ' + process_name}) : that.exitCli(cst.ERROR_EXIT);
}

var proc = processes[0];
// in case user searched by id/pid
process_name = proc.name;
if (proc.pm2_env.versioning) {
vizion.next({folder: proc.pm2_env.versioning.repo_path}, function(err, meta) {
if (err !== null)
Expand Down
22 changes: 22 additions & 0 deletions lib/Client.js
Original file line number Diff line number Diff line change
Expand Up @@ -717,3 +717,25 @@ Client.prototype.getProcessByName = function(name, cb) {
return cb(null, found_proc);
});
};

Client.prototype.getProcessByNameOrId = function (nameOrId, cb) {
var foundProc = [];

this.executeRemote('getMonitorData', {}, function (err, list) {
if (err) {
Common.printError('Error retrieving process list: ' + err);
return cb(err);
}

list.forEach(function (proc) {
if (proc.pm2_env.name === nameOrId ||
proc.pm2_env.pm_exec_path === path.resolve(nameOrId) ||
proc.pid === parseInt(nameOrId) ||
proc.pm2_env.pm_id === parseInt(nameOrId)) {
foundProc.push(proc);
}
});

return cb(null, foundProc);
});
};

0 comments on commit 0908e9a

Please sign in to comment.