{"action":"created","issue":{"url":"https://api.github.com/repos/Unitech/pm2/issues/2716","repository_url":"https://api.github.com/repos/Unitech/pm2","labels_url":"https://api.github.com/repos/Unitech/pm2/issues/2716/labels{/name}","comments_url":"https://api.github.com/repos/Unitech/pm2/issues/2716/comments","events_url":"https://api.github.com/repos/Unitech/pm2/issues/2716/events","html_url":"https://github.com/Unitech/pm2/issues/2716","id":207506534,"number":2716,"title":"PM2 programatic api .start ignores paramateres maxRestarts and restartDelay","user":{"login":"kharandziuk","id":3404755,"avatar_url":"https://avatars.githubusercontent.com/u/3404755?v=3","gravatar_id":"","url":"https://api.github.com/users/kharandziuk","html_url":"https://github.com/kharandziuk","followers_url":"https://api.github.com/users/kharandziuk/followers","following_url":"https://api.github.com/users/kharandziuk/following{/other_user}","gists_url":"https://api.github.com/users/kharandziuk/gists{/gist_id}","starred_url":"https://api.github.com/users/kharandziuk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kharandziuk/subscriptions","organizations_url":"https://api.github.com/users/kharandziuk/orgs","repos_url":"https://api.github.com/users/kharandziuk/repos","events_url":"https://api.github.com/users/kharandziuk/events{/privacy}","received_events_url":"https://api.github.com/users/kharandziuk/received_events","type":"User","site_admin":false},"labels":[{"id":106715799,"url":"https://api.github.com/repos/Unitech/pm2/labels/S:%20Need%20More%20Data","name":"S: Need More Data","color":"bfdadc","default":false}],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":6,"created_at":"2017-02-14T12:49:52Z","updated_at":"2017-02-14T15:13:03Z","closed_at":"2017-02-14T13:40:55Z","body":"So, I have a worker which tries to grab some data from web. I want to restart it on every fail and log the error. To monitor the worker process I use pm2. The simplified sample looks like:\r\n\r\nindex.js\r\n```\r\nconst pm2 = require('pm2');\r\n\r\npm2.connect(function(err) {\r\n    if (err) {\r\n          console.error(err);\r\n          process.exit(2);\r\n        }\r\n    pm2.start({\r\n          script    : 'populate.js',\r\n          exec_mode : 'cluster',\r\n          instances : 1,\r\n          autorestart: true,\r\n          max_memory_restart : '100M',\r\n          max_restarts: 1000 // or maxRestarts: 1000 documentation is inconsistent here\r\n    }, function(err) {\r\n      if (err) return console.error('Error while launching applications', err.stack || err);\r\n      console.log('PM2 and application has been succesfully started');\r\n      pm2.launchBus(function(err, bus) {\r\n        console.log('[PM2] Log streaming started');\r\n        bus.on('log:out', function(packet) {\r\n         console.log('[App:%s] %s', packet.process.name, packet.data);\r\n        });\r\n        bus.on('log:err', function(packet) {\r\n          console.error('[App:%s][Err] %s', packet.process.name, packet.data);\r\n        });\r\n      });\r\n    });\r\n});\r\n```\r\npopulate.js\r\n```\r\nconst Promise = require('bluebird');\r\n\r\nfunction populate() { // this function is just for illustration purpose\r\n  return Promise.delay(500)\r\n    .then(()=> Math.random() >= 0.5)\r\n    .then(flag => {\r\n      if(flag) {\r\n        console.log('populates db')\r\n        return populate()\r\n      } else {\r\n        throw new Error('something wrong')\r\n      }\r\n    })\r\n\r\n}\r\npopulate()\r\n```\r\nBut when I run script it doesn't restart scrapper more then 3 times(I expect 1000 times)\r\n```\r\n>    node index.js\r\n\r\nPM2 and application has been succesfully started\r\n[PM2] Log streaming started\r\n[App:populate] populates db\r\n\r\n\r\n[App:populate][Err]\r\nYou have triggered an unhandledRejection, you may\r\n[App:populate][Err]\r\nYou have triggered an unhandledRejection, you may\r\n[App:populate] populates db\r\n\r\n[App:populate][Err]\r\nYou have triggered an unhandledRejection, you may\r\n[App:populate][Err]\r\nYou have triggered an unhandledRejection, you may\r\n```\r\n\r\n#### Software versions used\r\n\r\n```\r\nOS         : os x 10.10.5\r\nnode.js    : v6.3.1\r\nPM2        : pm2@2.4.0\r\n```\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/Unitech/pm2/issues/comments/279734257","html_url":"https://github.com/Unitech/pm2/issues/2716#issuecomment-279734257","issue_url":"https://api.github.com/repos/Unitech/pm2/issues/2716","id":279734257,"user":{"login":"kharandziuk","id":3404755,"avatar_url":"https://avatars.githubusercontent.com/u/3404755?v=3","gravatar_id":"","url":"https://api.github.com/users/kharandziuk","html_url":"https://github.com/kharandziuk","followers_url":"https://api.github.com/users/kharandziuk/followers","following_url":"https://api.github.com/users/kharandziuk/following{/other_user}","gists_url":"https://api.github.com/users/kharandziuk/gists{/gist_id}","starred_url":"https://api.github.com/users/kharandziuk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kharandziuk/subscriptions","organizations_url":"https://api.github.com/users/kharandziuk/orgs","repos_url":"https://api.github.com/users/kharandziuk/repos","events_url":"https://api.github.com/users/kharandziuk/events{/privacy}","received_events_url":"https://api.github.com/users/kharandziuk/received_events","type":"User","site_admin":false},"created_at":"2017-02-14T15:13:03Z","updated_at":"2017-02-14T15:13:03Z","body":"```\r\nnode populate.js ; echo $?\r\npopulate\r\n0\r\n```"}}
{"actor":{"display_login":"kharandziuk"}}