<commit_before>{ argv } = require 'optimist'

koding = require './bongo'

parseServiceKey = require 'koding-service-key-parser'

allServices = {}

incService = (serviceKey, amount) ->
  serviceInfo = parseServiceKey serviceKey

  { serviceGenericName, serviceUniqueName } = serviceInfo

  fetchHostname serviceGenericName, serviceUniqueName, (err, hostname) ->

    allServices[serviceGenericName] ?= { seq: 0, services: {} }

    genericServices = allServices[serviceGenericName].services

    if genericServices[serviceUniqueName]?
    then genericServices[serviceUniqueName].amount += amount
    else genericServices[serviceUniqueName] = { amount, hostname }

    if genericServices[serviceUniqueName] is 0
      delete genericServices[serviceUniqueName]
    else if genericServices[serviceUniqueName] < 0
      console.error 'Negative service count!'

setInterval ->
  console.log allServices
, 3000

koding.connect ->
  koding.monitorPresence
    join: (serviceKey) ->
      incService serviceKey, 1
    leave: (serviceKey) ->
      incService serviceKey, -1

fetchHostname = (serviceGenericName, serviceUniqueName, callback) ->
  if 'broker' is serviceGenericName and not KONFIG.broker.useKontrold
    process.nextTick -> callback null,
      if KONFIG.broker.webPort?
      then "#{ KONFIG.broker.webHostname }:#{ KONFIG.broker.webPort }"
      else KONFIG.broker.webHostname
  else
    (koding.getClient().collection 'jKontrolWorkers')
      .findOne { serviceUniqueName }, { hostname: 1 },
        (err, worker) ->
          return callback err  if err?
          callback null, worker?.hostname ? null

module.exports = (req, res) ->
  {params:{service}, query} = req

  protocol = KONFIG.mq.webProtocol ? 'https:'

  genericServices = allServices[service]

  services = Object.keys(genericServices.services).map (k) ->
    genericServices.services[k].hostname ? k

  if query.all?
    res.send services.map (hostname) -> "#{ protocol }//#{ hostname }"
  else
    i = genericServices.seq++ % services.length
    res.set "Content-Type", "text/json"
    res.send "\"#{ protocol }//#{ services[i] }\""




<commit_msg>services endpoint: fix a typo, remove logs<commit_after>{ argv } = require 'optimist'

koding = require './bongo'

parseServiceKey = require 'koding-service-key-parser'

allServices = {}

incService = (serviceKey, amount) ->
  serviceInfo = parseServiceKey serviceKey

  { serviceGenericName, serviceUniqueName } = serviceInfo

  fetchHostname serviceGenericName, serviceUniqueName, (err, hostname) ->

    allServices[serviceGenericName] ?= { seq: 0, services: {} }

    genericServices = allServices[serviceGenericName].services

    if genericServices[serviceUniqueName]?
    then genericServices[serviceUniqueName].amount += amount
    else genericServices[serviceUniqueName] = { amount, hostname }

    if genericServices[serviceUniqueName] is 0
      delete genericServices[serviceUniqueName]
    else if genericServices[serviceUniqueName] < 0
      console.error 'Negative service count!'

koding.connect ->
  koding.monitorPresence
    join: (serviceKey) ->
      incService serviceKey, 1
    leave: (serviceKey) ->
      incService serviceKey, -1

fetchHostname = (serviceGenericName, serviceUniqueName, callback) ->
  if 'broker' is serviceGenericName and not KONFIG.broker.useKontrold
    process.nextTick -> callback null,
      if KONFIG.broker.webPort?
      then "#{ KONFIG.broker.webHostname }:#{ KONFIG.broker.webPort }"
      else KONFIG.broker.webHostname
  else
    (koding.getClient().collection 'jKontrolWorkers')
      .findOne { serviceUniqueName }, { hostname: 1 },
        (err, worker) ->
          return callback err  if err?
          callback null, worker?.hostname ? null

module.exports = (req, res) ->
  {params:{service}, query} = req

  protocol = KONFIG.broker.webProtocol ? 'https:'

  genericServices = allServices[service]

  services = Object.keys(genericServices.services).map (k) ->
    genericServices.services[k].hostname ? k

  if query.all?
    res.send services.map (hostname) -> "#{ protocol }//#{ hostname }"
  else
    i = genericServices.seq++ % services.length
    res.set "Content-Type", "text/json"
    res.send "\"#{ protocol }//#{ services[i] }\""





{'fraction_non_alphanumeric': 0.11667453944260746, 'fraction_numerical': 0.003778932451582428, 'mean_word_length': 3.7160356347438754, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 26, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6020965', 'n_tokens_mistral': 1278, 'n_tokens_neox': 1244, 'n_words': 286}