// Do a list of jobs in parallel, and return the List of futures immediately
324059
func ParallelDoWithLimit(jobs []func() interface{}, nThreads int) FutureGroup {
	if nThreads > len(jobs) {
		nThreads = len(jobs)
	}
	tp :=	NewPool(nThreads, len(jobs))
	tp.Start()
	defer func() {
		tp.Shutdown()
		tp.Wait()
	}()
	result := make([]*Future, len(jobs))
	for idx, nj := range(jobs) {
		result[idx] = tp.Submit(nj)
	}
	return FutureGroup{result}
}
1240076
func (p *Pool) getNextJobs(n int) ([]*Job, error) {
	p.RLock()
	thisId := p.id
	p.RUnlock()
	return getNextJobs(n, thisId)
}
900111
func (bs *BuildsService) List(opt *BuildListOptions) ([]Build, []Job, []Commit, *http.Response, error) {
	u, err := urlWithOptions("/builds", opt)
	if err != nil {
		return nil, nil, nil, nil, err
	}

	req, err := bs.client.NewRequest("GET", u, nil, nil)
	if err != nil {
		return nil, nil, nil, nil, err
	}

	var buildsResp listBuildsResponse
	resp, err := bs.client.Do(req, &buildsResp)
	if err != nil {
		return nil, nil, nil, resp, err
	}

	return buildsResp.Builds, buildsResp.Jobs, buildsResp.Commits, resp, err
}
744137
func (c *Client) Jobs(p *Printer) ([]*Job, error) {
	var mr multipartRequest
	mr.init()
	if p != nil {
		mr.WriteField("printerid", p.ID)
	}
	var resp jobsResponse
	err := jsonRPC(&c.auth, "POST", cloudprintURL+"/jobs", &mr, &resp)
	if err != nil {
		return nil, fmt.Errorf("Jobs: %v", err)
	}
	var jobs []*Job
	for _, desc := range resp.Jobs {
		jobs = append(jobs, desc.Job())
	}
	return jobs, nil
}
103062
func (p *ParallelManager) addWorker() {
	if atomic.LoadUint32(&p.workersNum) >= maxParallelWorkers {
		// Number of maximum workers is reached, no need to
		// to create a new one.
		return
	}

	// Update number of threads
	atomic.AddUint32(&p.workersNum, 1)

	// Start a new worker
	p.wg.Add(1)
	go func() {
		for {
			// Wait for jobs
			fn, ok := <-p.queueCh
			if !ok {
				// No more tasks, quit
				p.wg.Done()
				return
			}
			// Execute the task and send the result
			// to result channel.
			p.resultCh <- fn()
		}
	}()
}
414494
func listScheduledJobsAction(client *gocd.Client, c *cli.Context) (r interface{}, resp *gocd.APIResponse, err error) {
	return client.Jobs.ListScheduled(context.Background())
}
409233
func (s *Scheduler) RunPending() {
	runnableJobs, n := s.getRunnableJobs()

	if n != 0 {
		for i := 0; i < n; i++ {
			runnableJobs[i].run()
		}
	}
}
247407
func (t Tasks) Do(ctx context.Context) error {
	for _, a := range t {
		if err := a.Do(ctx); err != nil {
			return err
		}
	}
	return nil
}
887283
func (s *Server) Jobs(p *Printer) ([]*Job, error) {
	var mr multipartRequest
	mr.init()
	mr.WriteField("printerid", p.ID)

	var resp jobsResponse
	err := jsonRPC(&s.auth, "POST", cloudprintURL+"/fetch", &mr, &resp)
	if err != nil {
		return nil, fmt.Errorf("Jobs: %v", err)
	}

	var list []*Job
	for _, desc := range resp.Jobs {
		list = append(list, desc.Job())
	}
	return list, nil
}
68132
func (p *Process) ThreadList() []proc.Thread {
	r := make([]proc.Thread, 0, len(p.threads))
	for _, thread := range p.threads {
		r = append(r, thread)
	}
	return r
}
565273
func (j *Jobs) PrefixList(prefix string) ([]*JobListStub, *QueryMeta, error) {
	return j.List(&QueryOptions{Prefix: prefix})
}
792061
func (j *Jenkins) GetAllJobs() ([]*Job, error) {
	exec := Executor{Raw: new(ExecutorResponse), Jenkins: j}
	_, err := j.Requester.GetJSON("/", exec.Raw, nil)

	if err != nil {
		return nil, err
	}

	jobs := make([]*Job, len(exec.Raw.Jobs))
	for i, job := range exec.Raw.Jobs {
		ji, err := j.GetJob(job.Name)
		if err != nil {
			return nil, err
		}
		jobs[i] = ji
	}
	return jobs, nil
}
1193809
func (s V1ApplySpec) Jobs() []models.Job {
	jobsWithSource := []models.Job{}

	if s.RenderedTemplatesArchiveSpec != nil {
		for _, j := range s.JobSpec.JobTemplateSpecsAsJobs() {
			j.Source = s.RenderedTemplatesArchiveSpec.AsSource(j)
			j.Packages = s.Packages()
			jobsWithSource = append(jobsWithSource, j)
		}
	}

	return jobsWithSource
}
71452
func (s *Scheduler) getRunnableJobs() (running_jobs [MAXJOBNUM]*Job, n int) {
	runnableJobs := [MAXJOBNUM]*Job{}
	n = 0
	sort.Sort(s)
	for i := 0; i < s.size; i++ {
		if s.jobs[i].shouldRun() {

			runnableJobs[n] = s.jobs[i]
			//fmt.Println(runnableJobs)
			n++
		} else {
			break
		}
	}
	return runnableJobs, n
}
430728
func (s jobNamespaceLister) List(selector labels.Selector) (ret []*v1.Job, err error) {
	err = cache.ListAllByNamespace(s.indexer, s.namespace, selector, func(m interface{}) {
		ret = append(ret, m.(*v1.Job))
	})
	return ret, err
}
414921
func (v *ThreadPool) Submit(j JobFunc) *Future {
	if j == nil {
		panic("Can't submit nill function")
	}
	result := &Future{nil, make(chan bool, 1)}
	nj := &Job{j, result}
	v.jobs <- nj
	return result
}
1281772
func sortJobs(c context.Context, jobs []*engine.Job) sortedJobs {
	out := make(sortedJobs, len(jobs))
	for i, job := range jobs {
		out[i] = makeJob(c, job, nil)
	}
	sort.Sort(out)
	return out
}