Get a handler that calls Jenkins API to retrieve information about a job.
Job status and health reports will be logged when there's no error.

@param {Function} cb: callback for argument handling
@return Jenkins API handler function
513265
function read(cb) {
  return function (name, args) {
    function resultCb(result) {
      var status = util.statusByColor(result.color);
      var color  = util.colorByStatus(status, result.color);
      console.log('%s | %s', name, text.__(status)[color]);
      result.healthReport.forEach(function (report) {
        console.log(' - %s', report.description);
      });
    }
    function jenkinsCb(jenkins) {
      jenkins.readJob(name, cli.exitCb(null, resultCb));
    }
    cb(args, jenkinsCb);
  };
}
737016
function service(root, cb) {
    var registryPath = config.registryPath || path.join(root, 'registry');
    fs.mkdir(registryPath, function(err) {
      if (err && err.code !== 'EEXIST') {
        logger.error(err);
        return cb(err);
      }

      // swallow errors, it may exists
      var server = registry({
        dir: registryPath
      });

      server.on('error', function(err) {
        logger.error(err);
      });

      server.listen(config.registryPort, function(err) {
        logger.info({
          port: config.registryPort,
          path: registryPath
        }, 'registry started');

        if (typeof err === 'string') {
          // err will contains the ip
          // TODO remove me as https://github.com/mafintosh/root/issues/12 get fixes
          err = null;
        }

        if (cb) {
          cb(err, server);
        }
      });
    });
  }
430906
function (cb) {
            if (cb) {
                if (isPromise(cb)) {
                    cb = cb.errback;
                }
                if (this.__fired && this.__error) {
                    this.__callNextTick(cb, this.__error);
                } else {
                    this.__errorCbs.push(cb);
                }
            }
            return this;
        }
1133239
function getMongooseConnection(mongoDbUrl, logger, cb) {
  logger.debug("creating mongoose connection for data_source_update job", {mongoDbUrl: mongoDbUrl});
  var mongooseConnection = mongoose.createConnection(mongoDbUrl);
  return cb(undefined, mongooseConnection);
}
967151
function(cb) {
  return function(err, res, body) {
    if (typeof cb !== 'function') return;

    // Catch connection errors
    if (err || !res) {
      var returnErr = 'Error connecting to Unbabel';
      if (err) returnErr += ': ' + err.code;
      err = returnErr;
    } else if (res.statusCode !== 200 && res.statusCode !== 201 && res.statusCode !== 202) {
      err = 'Something went wrong. Unbabel responded with a ' + res.statusCode;
    }
    if (err) return cb(err, null);

    // Try to parse response
    if (body !== Object(body)) {
      try {
        body = JSON.parse(body);
      } catch(e) {
        return cb('Could not parse response from Unbabel: ' + body, null);
      }
    }

    // Check for error returned in a 200 response
    if (body.opstat === 'error') {
      if (body.err) return cb(body.err);
      return cb(err);
    }

    // Make sure response is OK
    if (body.opstat === 'ok') body = body.response;

    // Return response
    cb(null, body);
  };
}
1064985
function update(cb) {
  return function (name, configFile, args) {
    function resultCb(result) {
      console.log(text.__('Job %s was updated successfully'), name);
    }
    function jenkinsCb(jenkins) {
      var config = fs.readFileSync(configFile).toString();
      jenkins.updateJob(name, config, cli.exitCb(null, resultCb));
    }
    cb(args, jenkinsCb);
  };
}
473389
function (id, options, cb) {
    if (arguments.length !== 3) {
      cb = options;
      options = {};
    }
    var self = this;
    var model = this.get(id);
    if (model){
      return cb(null, model);
    }
    function done() {
      var model = self.get(id);
      if (model) {
        if (cb){
          cb(null, model);
        }
      } else {
        cb(new Error('not found'));
      }
    }
    if (options.all) {
      this.fetch({
        callback: done
      });
    } else {
      this.fetchById(id, cb);
    }
  }
869320
function salute (cb) {
  return (req, res, ...args) => {
    var value = null
    try {
      value = cb(req, res, ...args) || ''
    } catch (e) {
      value = e
    }
    return stream(Promise.resolve(value).then(type(res)))
      .on('error', status(res))
  }
}
1085575
def call_nowait(self, cb_name):
        
        if self.bootstrapping:
            return
        if cb_name in (ACTION_ON_START, ACTION_ON_STOP, ACTION_ON_RESTART, ACTION_ON_ROLE_CHANGE):
            self.__cb_called = True

        if self.callback and cb_name in self.callback:
            cmd = self.callback[cb_name]
            try:
                cmd = shlex.split(self.callback[cb_name]) + [cb_name, self.role, self.scope]
                self._callback_executor.call(cmd)
            except Exception:
                logger.exception('callback %s %s %s %s failed', cmd, cb_name, self.role, self.scope)
1297413
function cb(err) {
        if (callback) {
            if (err) return callback(err);
            callback(null, rec);
        }
        callback = null;
        if (!err) {
            that.emit('logged', rec);
        }
    }
552949
function(){

		var view = "_design/searchJob/_view/jobstatus?key=" + JSON.stringify('UPLOADING');
	    return server.methods.clusterprovider.getView(view)
	    .then(function(docs){
	    	return Promise.map(_.pluck(docs, "value"), server.methods.cronprovider.addJobToUpdateQueue);
	    })
	    .catch(console.error);
		
	}
777103
function access(cb, force){
						_this.login(function(login_result, login_accesskey){
							// console.log(login_result, login_accesskey);
							if( login_result === false && login_accesskey === false ){
								cb(null, false, 0, {});
								return;
							}
							_this.httpRequest(
								url,
								{
									'params': options ,
									'method': apiSettings.method
								},
								function(bin, status, responseHeaders){
									if( !status ){
										cb(false, false, 0, {});
										return;
									}
									try {
										bin = JSON.parse(bin);
									} catch (e) {
									}
									// console.log(bin);
									if( bin.return_code !== 0 ){
										if(force){
											cb(null, bin, status, responseHeaders);
											return;
										}
										setTimeout(function(){
											access(cb, true);
										}, 1000);
										return;
									}
									cb(bin.list, bin, status, responseHeaders);
									return;
								}
							);
						}, force);

					}
701991
function Jenkins(opts) {
  if (!(this instanceof Jenkins)) {
    return new Jenkins(opts);
  }

  if (typeof opts === 'string') {
    opts = { baseUrl: opts };
  } else {
    opts = opts || {};
  }

  opts = Object.assign({}, opts);

  if (!opts.baseUrl) {
    if (opts.url) {
      opts.baseUrl = opts.url;
      delete opts.url;
    } else {
      throw new Error('baseUrl required');
    }
  }

  if (!opts.headers) {
    opts.headers = {};
  }
  if (!opts.headers.referer) {
    opts.headers.referer = opts.baseUrl + '/';
  }

  if (opts.request) {
    throw new Error('request not longer supported');
  }

  opts.name = 'jenkins';

  if (typeof opts.crumbIssuer === 'function') {
    this._crumbIssuer = opts.crumbIssuer;
    delete opts.crumbIssuer;
  } else if (opts.crumbIssuer === true) {
    this._crumbIssuer = utils.crumbIssuer;
  }

  if (opts.formData) {
    if (typeof opts.formData !== 'function' || opts.formData.name !== 'FormData') {
      throw new Error('formData is invalid');
    }
    this._formData = opts.formData;
    delete opts.formData;
  }

  papi.Client.call(this, opts);

  this._ext('onCreate', this._onCreate);
  this._ext('onResponse', this._onResponse);

  this.build = new Jenkins.Build(this);
  this.crumbIssuer = new Jenkins.CrumbIssuer(this);
  this.job = new Jenkins.Job(this);
  this.label = new Jenkins.Label(this);
  this.node = new Jenkins.Node(this);
  this.queue = new Jenkins.Queue(this);
  this.view = new Jenkins.View(this);

  try {
    if (opts.promisify) {
      if (typeof opts.promisify === 'function') {
        papi.tools.promisify(this, opts.promisify);
      } else {
        papi.tools.promisify(this);
      }
    }
  } catch (err) {
    err.message = 'promisify: ' + err.message;
    throw err;
  }
}
1096212
function(server, cb) {
    var port = _getServerConfig(server).port || 3223;
    var result = {running: false, port: port, listening: false};
    var host = 'localhost';

    var pidFile = path.join(nscaleRoot, 'data', '.' + server);

    portscanner.checkPortStatus(port, host, function(err, status) {
      if (err) { return cb(err); }
      result.listening = (status === 'open') ? true : false;

      if (fs.existsSync(pidFile)) {
        var pid = Number(fs.readFileSync(pidFile));
        result.pid = pid;

        running(pid, function(err, running) {
          if (err) { cb(err); }
          result.running = running;
          cb(null, result);
        });
      }
      else { 
        cb(null, result); 
      }
    });
  }
818665
function fetch(cb) {
  let resp = ''
  let json = {}

  process.env.EDAM_COMPLETE && console.log(' Get branches list: %s', url)
  https
    .request(
      Object.assign(
        {
          headers: {
            'User-Agent':
              'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36'
          }
        },
        u.parse(url)
      ),
      function(income) {
        income.on('data', function(chunk) {
          resp += chunk.toString()
        })
        income
          .on('end', function() {
            json = JSON.parse(resp)
            process.env.EDAM_COMPLETE && console.log('Response: \n', json)

            let transform = function (branch) {
              return REPO + '?checkout=' + branch
            }
            cb(
              json.map(function(x) {
                return transform(x.name)
              })
            )
          })
          .on('error', console.error)
      }
    )
    .end()
}
1098111
function GET(path, cb) {
  // console.log(`### ${endpoint}${path}`);
  (0, _request2.default)({ url: '' + endpoint + path, json: true, timeout: timeout }, function (err, res, body) {
    if (err || !res || res.statusCode >= 400) {
      var statusCode = res ? res.statusCode : 0,
          statusMessage = res ? res.statusMessage : 'Unspecified error (likely a timeout)';

      if (statusCode === 429) {
        var headers = res.headers || {},
            limit = headers['x-rate-limit-limit'] || 'N/A',
            interval = headers['x-rate-limit-interval'] || 'N/A';
        return cb(new Error('Rate limit exceeded: ' + limit + ' requests in ' + interval));
      }
      if (statusCode === 404) return cb(new Error('Not found on CrossRef: \'' + endpoint + path + '\''));
      var msg = err && err.message ? err.message : statusMessage;
      return cb(new Error('CrossRef error: [' + statusCode + '] ' + msg));
    }
    if ((typeof body === 'undefined' ? 'undefined' : _typeof(body)) !== 'object') return cb(new Error('CrossRef response was not JSON: ' + body));
    if (!body.status) return cb(new Error('Malformed CrossRef response: no `status` field.'));
    if (body.status !== 'ok') return cb(new Error('CrossRef error: ' + body.status));
    cb(null, body.message);
  });
}
475856
function responseHandler(params, cb) {

  return function handleResponse(err, httpResponse, body) {
    body = body || "{}";
    httpResponse = httpResponse || {};

    //The response should be JSON. If it is a string, then the response should be parsed.
    if (_.isString(body)) {
      try {
        body = JSON.parse(body);
      } catch (e) {
        log.logger.error("FH-MBAAS-CLIENT: Invalid Response Body ", {body: body});
      }
    }

    log.logger.debug("FH-MBAAS-CLIENT:  Request Finish ", {
      err: err,
      httpResponse: httpResponse.statusCode,
      body: body
    });

    // provide defaults
    if (httpResponse && httpResponse.statusCode >= 400) {
      err = err || {};
      err.httpCode = httpResponse.statusCode;
      err.message = "Unexpected Status Code " + httpResponse.statusCode;
    }

    //There is a specific error message if an environment is unreachable
    if (httpResponse && httpResponse.statusCode === 503) {
      err = {
        httpCode: 503,
        message: CONSTANTS.ERROR_MESSAGES.ENVIRONMENT_UNREACHABLE.replace('{{ENVLABEL}}', params.envLabel || "")
      };
    }

    // MbaaS unavailable
    if (err && err.code !== undefined && (err.code === "ENOTFOUND" || err.code === "ETIMEDOUT")) {
      err = {
        httpCode: httpResponse.statusCode || 500,
        message: "MBaaS environment is not reachable. Please make the environment available or delete it. Environment Label - " + params.envLabel || ""
      };
    }

    if (err) {
      cb(err || body || "Unexpected Status Code " + httpResponse.statusCode);
    } else {
      cb(undefined, body);
    }
  };
}