summaryrefslogtreecommitdiffstats
path: root/vnfmarket/src/main/webapp/vnfmarket/node_modules/karma/lib/launchers/retry.js
blob: 3df67c8ed4ccaa4bfcf00cc895e6e620687a49c0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
var log = require('../logger').create('launcher')

var RetryLauncher = function (retryLimit) {
  var self = this

  this._retryLimit = retryLimit

  this.on('done', function () {
    if (!self.error) {
      return
    }

    if (self._retryLimit > 0) {
      var attempt = retryLimit - self._retryLimit + 1
      log.info('Trying to start %s again (%d/%d).', self.name, attempt, retryLimit)
      self.restart()
      self._retryLimit--
    } else if (self._retryLimit === 0) {
      log.error('%s failed %d times (%s). Giving up.', self.name, retryLimit, self.error)
    } else {
      log.debug('%s failed (%s). Not restarting.', self.name, self.error)
    }
  })
}

RetryLauncher.decoratorFactory = function () {
  return function (launcher) {
    RetryLauncher.call(launcher, 2)
  }
}

module.exports = RetryLauncher