       cluster: job_result.terms('_cid')
   res.limits = {} # may not be worth reporting on limit index in new structure
   job_limit.each 'NOT last:*', (lm) -> res.limits[lm.group ? lm._id] = {date:lm.created_date,limit:lm.limit}
-  job_job.each 'NOT done:true', {_source:['_id','count','processed']}, (j) -> res.jobs.waiting += (j.count - (j.processed ? 0))
   res.caps = {}
   job_cap.each '*', (cp) -> res.caps[cp.group ? cp._id] = {date:cp.created_date}
   return res


API.job.progress = (jobid) ->
  job = if typeof jobid is 'object' then jobid else job_job.get jobid
  progress = if job.done then 100 else if job.new then 0 else (job.processed ? 0)/job.count*100
  progress = 100 if progress > 100
  if progress is 100 and job.done isnt true
    API.job.complete job
  res = {running: API.job.running(), createdAt:job.createdAt, progress:progress, name:job.name, email:job.email, _id:job._id, new:job.new, count: job.count, processes: job.count, processed: job.processed ? 0}
  if progress isnt 100
    if res.running
      if Date.now() > (job.createdAt + (2000 * job.count)) and (Date.now() - (job.updatedAt ? 0)) > ((job.count - (job.processed ? 0)) * 2000)
        res.stuck = true
        res.missing = []
        res.waiting = 0
        res.processing = 0
        res.results = 0
        if typeof job.processes is 'object'
          for p in job.processes
            if job_processing.get(p._id) then res.processing += 1 else if job_process.get(p._id) then res.waiting += 1 else if job_result.get(p._id)? then res.results += 1 else res.missing.push(p._id)
        res.missed = res.missing.length
        if res.missed
          API.log 'Job progress checked for job ' + job._id + ', but processes are missing...' # TODO should this send an email warning to admin, to the job submitter, should it resubmit the missing processes?
    else
      API.log 'Job progress checked for job ' + job._id + ', but job runner is not running...' # TODO should this send an email warning to admin?
    if res.count is res.results
      res.progress = 100
      API.job.complete job
  return res

API.job.complete = (jobid='NOT done:true', set_done=true, run_complete=true, list=false, known=0) ->

      rs = job_process.find({'signature.exact':proc.signature}, true) if not rs?
      if rs
        proc._id = rs._id
        try
          rs.job.push job._id
          try job_process.update rs._id, {job: rs.job}
          try job_processing.update rs._id, {job: rs.job}
          try job_result.update rs._id, {job: rs.job}
      else
        proc._id = Random.id()
        imports.push proc
