// GetJob returns the list of jobs you currently have.
973391
func (s *JobClient) Get(ctx context.Context, input *GetJobInput) (*GetJobOutput, error) {
	fullPath := path.Join("/", s.client.AccountName, "jobs", input.JobID, "live", "status")

	reqInput := client.RequestInput{
		Method: http.MethodGet,
		Path:   fullPath,
	}
	respBody, _, err := s.client.ExecuteRequestStorage(ctx, reqInput)
	if respBody != nil {
		defer respBody.Close()
	}
	if err != nil {
		return nil, errors.Wrap(err, "unable to get job")
	}

	job := &Job{}
	decoder := json.NewDecoder(respBody)
	if err = decoder.Decode(&job); err != nil {
		return nil, errors.Wrap(err, "unable to decode get job response")
	}

	return &GetJobOutput{
		Job: job,
	}, nil
}
260826
func (j *Jenkins) BuildJob(name string, options ...interface{}) (int64, error) {
	job := Job{Jenkins: j, Raw: new(JobResponse), Base: "/job/" + name}
	var params map[string]string
	if len(options) > 0 {
		params, _ = options[0].(map[string]string)
	}
	return job.InvokeSimple(params)
}
232535
func (e *engineImpl) GetVisibleJob(c context.Context, jobID string) (*Job, error) {
	job, err := e.getJob(c, jobID)
	switch {
	case err != nil:
		return nil, err
	case job == nil || !job.Enabled:
		return nil, ErrNoSuchJob
	}
	if err := job.CheckRole(c, acl.Reader); err != nil {
		if err == ErrNoPermission {
			err = ErrNoSuchJob // pretend protected jobs don't exist
		}
		return nil, err
	}
	return job, nil
}
361005
func (client Client) GetJobs() (map[string]JobDescriptor, error) {
	retry := retry.New(3, retry.DefaultBackoffFunc)

	var data []byte
	work := func() error {
		req, err := http.NewRequest("GET", fmt.Sprintf("%s/api/json/jobs", client.baseURL.String()), nil)
		if err != nil {
			return err
		}
		req.Header.Set("Accept", "application/json")
		req.SetBasicAuth(client.userName, client.password)

		var responseCode int
		responseCode, data, err = consumeResponse(req)
		if err != nil {
			return err
		}

		if responseCode != http.StatusOK {
			Log.Printf("%s", string(data))
			return fmt.Errorf("%s", string(data))
		}

		return nil
	}

	if err := retry.Try(work); err != nil {
		return nil, err
	}

	var t Jobs
	if err := json.Unmarshal(data, &t); err != nil {
		return nil, err
	}

	jobs := make(map[string]JobDescriptor)
	for _, v := range t.Jobs {
		jobs[v.Name] = v
	}
	return jobs, nil
}
1136740
func (e *engineImpl) GetDebugJobState(c context.Context, jobID string) (*DebugJobState, error) {
	job, err := e.getJob(c, jobID)
	switch {
	case err != nil:
		return nil, errors.Annotate(err, "failed to fetch Job entity").Err()
	case job == nil:
		return nil, ErrNoSuchJob
	}

	state := &DebugJobState{Job: job}

	// Fill in FinishedInvocations.
	state.FinishedInvocations, err = unmarshalFinishedInvs(job.FinishedInvocationsRaw)
	if err != nil {
		return nil, errors.Annotate(err, "failed to unmarshal FinishedInvocationsRaw").Err()
	}

	// Fill in RecentlyFinishedSet.
	finishedSet := recentlyFinishedSet(c, jobID)
	listing, err := finishedSet.List(c)
	if err != nil {
		return nil, errors.Annotate(err, "failed to fetch recentlyFinishedSet").Err()
	}
	state.RecentlyFinishedSet = make([]int64, len(listing.Items))
	for i, itm := range listing.Items {
		state.RecentlyFinishedSet[i] = finishedSet.ItemToInvID(&itm)
	}

	// Fill in PendingTriggersSet.
	triggersSet := pendingTriggersSet(c, jobID)
	_, state.PendingTriggersSet, err = triggersSet.Triggers(c)
	if err != nil {
		return nil, errors.Annotate(err, "failed to fetch pendingTriggersSet").Err()
	}

	// Ask the corresponding task.Manager to fill in DebugManagerState. Pass it
	// a phony controller configured just enough to be useful for fetching the
	// state, but not anything else.
	ctl, err := controllerForInvocation(c, e, &Invocation{
		ID:    -1,
		JobID: jobID,
		Task:  job.Task,
	})
	if err == nil {
		state.ManagerState, err = ctl.manager.GetDebugState(c, ctl)
	}
	if state.ManagerState == nil {
		state.ManagerState = &internal.DebugManagerState{}
	}
	if err != nil {
		state.ManagerState.Error = err.Error()
	}
	if ctl != nil {
		state.ManagerState.DebugLog = ctl.debugLog
	}

	return state, nil
}
1060061
func (e *engineImpl) GetVisibleJobs(c context.Context) ([]*Job, error) {
	q := ds.NewQuery("Job").Eq("Enabled", true)
	return e.queryEnabledVisibleJobs(c, q)
}
236224
func (d *ddl) getHistoryDDLJob(id int64) (*model.Job, error) {
	var job *model.Job

	err := kv.RunInNewTxn(d.store, false, func(txn kv.Transaction) error {
		t := meta.NewMeta(txn)
		var err1 error
		job, err1 = t.GetHistoryDDLJob(id)
		return errors.Trace(err1)
	})

	return job, errors.Trace(err)
}
48666
func (worker *Worker) RegisterJob(job *Job) error {
	if worker.mounted {
		debug.PrintStack()
		fmt.Printf("Job should be registered before Worker mounted into admin, but %v is registered after that", job.Name)
	}

	job.Worker = worker
	worker.Jobs = append(worker.Jobs, job)
	return nil
}
1125283
func GetDDLJobs(txn kv.Transaction) ([]*model.Job, error) {
	t := meta.NewMeta(txn)
	generalJobs, err := getDDLJobsInQueue(t, meta.DefaultJobListKey)
	if err != nil {
		return nil, errors.Trace(err)
	}
	addIdxJobs, err := getDDLJobsInQueue(t, meta.AddIndexJobListKey)
	if err != nil {
		return nil, errors.Trace(err)
	}
	jobs := append(generalJobs, addIdxJobs...)
	sort.Sort(jobArray(jobs))
	return jobs, nil
}
851497
func (f *ClusterFixer) FindAppReleaseJobs(app, typ string) []map[string]*host.Job {
	var sortReleases ReleasesByCreate
	releases := make(map[string]map[string]*host.ActiveJob) // map of releaseID -> hostID -> job ordered
	// connect to each host, list jobs, find distinct releases
	for _, h := range f.hosts {
		jobs, err := h.ListJobs()
		if err != nil {
			f.l.Error("error listing jobs", "host", h.ID(), "error", err)
			continue
		}
		for _, j := range jobs {
			if j.Job.Metadata["flynn-controller.app_name"] != app || j.Job.Metadata["flynn-controller.type"] != typ {
				continue
			}
			id := j.Job.Metadata["flynn-controller.release"]
			if id == "" {
				continue
			}
			m, ok := releases[id]
			if !ok {
				sortReleases = append(sortReleases, SortableRelease{id, j.StartedAt})
				m = make(map[string]*host.ActiveJob)
				releases[id] = m
			}
			if curr, ok := m[h.ID()]; ok && curr.StartedAt.Before(j.StartedAt) {
				continue
			}
			jobCopy := j
			m[h.ID()] = &jobCopy
		}
	}
	sort.Sort(sortReleases)
	res := make([]map[string]*host.Job, len(sortReleases))
	for i, r := range sortReleases {
		res[i] = make(map[string]*host.Job, len(releases[r.id]))
		for k, v := range releases[r.id] {
			res[i][k] = v.Job
		}
	}
	return res
}
546429
func (s *StoreToJobLister) GetPodJobs(pod *api.Pod) (jobs []extensions.Job, err error) {
	var selector labels.Selector
	var job extensions.Job

	if len(pod.Labels) == 0 {
		err = fmt.Errorf("no jobs found for pod %v because it has no labels", pod.Name)
		return
	}

	for _, m := range s.Store.List() {
		job = *m.(*extensions.Job)
		if job.Namespace != pod.Namespace {
			continue
		}

		selector, _ = unversioned.LabelSelectorAsSelector(job.Spec.Selector)
		if !selector.Matches(labels.Set(pod.Labels)) {
			continue
		}
		jobs = append(jobs, job)
	}
	if len(jobs) == 0 {
		err = fmt.Errorf("could not find jobs for pod %s in namespace %s with labels: %v", pod.Name, pod.Namespace, pod.Labels)
	}
	return
}
997000
func getJob(client *api.Client, jobID string, version *uint64) (*api.Job, error) {
	if version == nil {
		job, _, err := client.Jobs().Info(jobID, nil)
		return job, err
	}

	versions, _, _, err := client.Jobs().Versions(jobID, false, nil)
	if err != nil {
		return nil, err
	}

	for _, j := range versions {
		if *j.Version != *version {
			continue
		}
		return j, nil
	}

	return nil, fmt.Errorf("job %q with version %d couldn't be found", jobID, *version)
}
1253204
func (p *ReadOnlySchedulerClient) GetJobUpdateDetails(ctx context.Context, query *JobUpdateQuery) (r *Response, err error) {
  var _args72 ReadOnlySchedulerGetJobUpdateDetailsArgs
  _args72.Query = query
  var _result73 ReadOnlySchedulerGetJobUpdateDetailsResult
  if err = p.Client_().Call(ctx, "getJobUpdateDetails", &_args72, &_result73); err != nil {
    return
  }
  return _result73.GetSuccess(), nil
}
1132757
func (j *JobGetter) ApiJob(jpath string) (*api.Job, error) {
	var jobfile io.Reader
	switch jpath {
	case "-":
		if j.testStdin != nil {
			jobfile = j.testStdin
		} else {
			jobfile = os.Stdin
		}
	default:
		if len(jpath) == 0 {
			return nil, fmt.Errorf("Error jobfile path has to be specified.")
		}

		job, err := ioutil.TempFile("", "jobfile")
		if err != nil {
			return nil, err
		}
		defer os.Remove(job.Name())

		if err := job.Close(); err != nil {
			return nil, err
		}

		// Get the pwd
		pwd, err := os.Getwd()
		if err != nil {
			return nil, err
		}

		client := &gg.Client{
			Src: jpath,
			Pwd: pwd,
			Dst: job.Name(),
		}

		if err := client.Get(); err != nil {
			return nil, fmt.Errorf("Error getting jobfile from %q: %v", jpath, err)
		} else {
			file, err := os.Open(job.Name())
			defer file.Close()
			if err != nil {
				return nil, fmt.Errorf("Error opening file %q: %v", jpath, err)
			}
			jobfile = file
		}
	}

	// Parse the JobFile
	jobStruct, err := jobspec.Parse(jobfile)
	if err != nil {
		return nil, fmt.Errorf("Error parsing job file from %s: %v", jpath, err)
	}

	return jobStruct, nil
}
836071
func (s *SchedulerServer) getJob(ctx context.Context, ref *scheduler.JobRef) (*engine.Job, error) {
	jobID := ref.GetProject() + "/" + ref.GetJob()
	switch job, err := s.Engine.GetVisibleJob(ctx, jobID); {
	case err == nil:
		return job, nil
	case err == engine.ErrNoSuchJob:
		return nil, status.Errorf(codes.NotFound, "no such job or no READ permission")
	default:
		return nil, status.Errorf(codes.Internal, "internal error when fetching job: %s", err)
	}
}
616836
func (job *Job) GetQueue() Queue {
	if job.Queue != nil {
		return job.Queue
	}
	return job.Worker.Queue
}
987944
func (p *ReadOnlySchedulerClient) PopulateJobConfig(ctx context.Context, description *JobConfiguration) (r *Response, err error) {
  var _args68 ReadOnlySchedulerPopulateJobConfigArgs
  _args68.Description = description
  var _result69 ReadOnlySchedulerPopulateJobConfigResult
  if err = p.Client_().Call(ctx, "populateJobConfig", &_args68, &_result69); err != nil {
    return
  }
  return _result69.GetSuccess(), nil
}