'use strict';

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.monitorServiceProgress = monitorServiceProgress;

function _asyncToGenerator(fn) { return function () { var gen = fn.apply(this, arguments); return new Promise(function (resolve, reject) { function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { return Promise.resolve(value).then(function (value) { step("next", value); }, function (err) { step("throw", err); }); } } return step("next"); }); }; }

function check(session) {
  return new Promise(function (resolve, reject) {
    session.execute('docker service inspect ' + serviceName + ' --format=\'{{json .}}\'', function (err, output) {
      console.dir({
        err: err,
        output: output
      });
    });
  });
}

function monitorServiceProgress(taskList, serviceName, newImage) {
  var _this = this;

  taskList.executeFunction('Waiting for service to update', function () {
    var _ref = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee(session) {
      return regeneratorRuntime.wrap(function _callee$(_context) {
        while (1) {
          switch (_context.prev = _context.next) {
            case 0:
              _context.next = 2;
              return check(session);

            case 2:
            case 'end':
              return _context.stop();
          }
        }
      }, _callee, _this);
    }));

    return function (_x) {
      return _ref.apply(this, arguments);
    };
  }());

  return taskList;
}
//# sourceMappingURL=monitor-service.js.map