Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: make "pull", "backward" and "forward" works with id and pid #3484

Merged
merged 1 commit into from
Mar 2, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
});
};