<commit_before>_ = require('underscore')
config = require('./config')
async = require('async')
PulsarApiClient = require('./pulsar-api-client')

class PulsarApi

  _clientMap = {}

  constructor: ()->
    pulsarApiConfig = config.pulsarApi

    clientDefaultConfig = _.pick(pulsarApiConfig, 'url', 'token')
    @_clientDefault = new PulsarApiClient(clientDefaultConfig.url, clientDefaultConfig.authToken)

    _.each pulsarApiConfig.auxiliary, (clientConfig, key) ->
      clientConfig = _.defaults({}, clientConfig, clientDefaultConfig)
      _clientMap[key] = new PulsarApiClient(clientConfig.url, clientConfig.authToken)

  getClientDefault: () ->
    @_clientDefault

  getClient: (app, env) ->
    name = @_getClientName(app, env)
    if (_clientMap[name])
      _clientMap[name]
    else
      @getClientDefault()

  runJob: (job) ->
    client = @getClient(job.app, job.env)
    client.runJob(job)

  jobs: (callback) ->
    clientList = _.toArray(_clientMap)
    clientList.unshift @_clientDefault

    getClientJobs = (client, callback) ->
      client.jobs(callback)

    async.map clientList, getClientJobs, (results) ->
      concatenator = (all, items) ->
        all.concat items<commit_msg>Clarify PulsarApi construction. Remove the default config extending redundancy.<commit_after>_ = require('underscore')
config = require('./config')
async = require('async')
PulsarApiClient = require('./pulsar-api-client')

class PulsarApi

  _clientMap = {}

  constructor: ()->
    pulsarApiConfig = config.pulsarApi
    @_clientDefault = new PulsarApiClient(pulsarApiConfig.url, pulsarApiConfig.authToken)
    _.each pulsarApiConfig.auxiliary, (clientConfig, key) ->
      _clientMap[key] = new PulsarApiClient(clientConfig.url, clientConfig.authToken)

  getClientDefault: () ->
    @_clientDefault

  getClient: (app, env) ->
    name = @_getClientName(app, env)
    if (_clientMap[name])
      _clientMap[name]
    else
      @getClientDefault()

  runJob: (job) ->
    client = @getClient(job.app, job.env)
    client.runJob(job)

  jobs: (callback) ->
    clientList = _.toArray(_clientMap)
    clientList.unshift @_clientDefault

    getClientJobs = (client, callback) ->
      client.jobs(callback)

    async.map clientList, getClientJobs, (results) ->
      concatenator = (all, items) ->
        all.concat items
{'fraction_non_alphanumeric': 0.1262344353799914, 'fraction_numerical': 0.0, 'mean_word_length': 3.745417515274949, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 21, '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': '731461', 'n_tokens_mistral': 757, 'n_tokens_neox': 734, 'n_words': 143}