<commit_before>class ComputeController extends KDController

  @providers = KD.config.providers

  @timeout = 5000

  constructor:->
    super

    { mainController, kontrol } = KD.singletons

    mainController.ready =>

      @kloud         = kontrol.getKite
        name         : "kloud"
        environment  : KD.config.environment

      @eventListener = new ComputeEventListener

      @on "MachineBuilt",   @bound 'reset'
      @on "MachineDestroy", @bound 'reset'

      @fetchStacks => @emit 'ready'


  fetchStacks: (callback = noop)->

    if @stacks
      callback null, @stacks
      info "Stacks returned from cache."
      return

    KD.remote.api.JStack.some {}, (err, stacks = [])=>
      return callback err  if err?

      if stacks.length > 0

        machines = []
        stacks.forEach (stack)->
          stack.machines.forEach (machine, index)->
            machine = new Machine { machine }
            stack.machines[index] = machine
            machines.push machine

        @machines = machines
        @stacks   = stacks
        callback null, stacks

      else
        callback null, []


  fetchMachines: do (queue=[])->

    (callback = noop)-> KD.singletons.mainController.ready =>

      if @machines
        callback null, @machines
        info "Machines returned from cache."
        return

      return  if (queue.push callback) > 1

      @fetchStacks (err, stacks)=>

        if err?
          cb err  for cb in queue
          queue = []
          return

        machines = []
        stacks.forEach (stack)->
          stack.machines.forEach (machine)->
            machines.push machine
<commit_msg>ComputeController: queue up fetchStacks requests<commit_after>class ComputeController extends KDController

  @providers = KD.config.providers

  @timeout = 5000

  constructor:->
    super

    { mainController, kontrol } = KD.singletons

    mainController.ready =>

      @kloud         = kontrol.getKite
        name         : "kloud"
        environment  : KD.config.environment

      @eventListener = new ComputeEventListener

      @on "MachineBuilt",   => do @reset
      @on "MachineDestroy", => do @reset

      @fetchStacks => @emit 'ready'


  fetchStacks: do (queue=[])->

    (callback = noop)-> KD.singletons.mainController.ready =>

      if @stacks
        callback null, @stacks
        info "Stacks returned from cache."
        return

      return  if (queue.push callback) > 1

      KD.remote.api.JStack.some {}, (err, stacks = [])=>

        if err?
          cb err  for cb in queue
          queue = []
          return

        if stacks.length > 0

          machines = []
          stacks.forEach (stack)->
            stack.machines.forEach (machine, index)->
              machine = new Machine { machine }
              stack.machines[index] = machine
              machines.push machine

          @machines = machines
          @stacks   = stacks
          cb null, stacks  for cb in queue

        else
          cb null, []  for cb in queue

        queue = []


  fetchMachines: do (queue=[])->

    (callback = noop)-> KD.singletons.mainController.ready =>

      if @machines
        callback null, @machines
        info "Machines returned from cache."
        return

      return  if (queue.push callback) > 1

      @fetchStacks (err, stacks)=>

        if err?
          cb err  for cb in queue
          queue = []
          return

        machines = []
        stacks.forEach (stack)->
          stack.machines.forEach (machine)->
            machines.push machine

{'fraction_non_alphanumeric': 0.0991016282987086, 'fraction_numerical': 0.0036496350364963502, 'mean_word_length': 1.8077226162332545, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 38, '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': '4255356', 'n_tokens_mistral': 1055, 'n_tokens_neox': 948, 'n_words': 276}