Beispiel #1
0
func (r *JobRepo) Get(id string) (*ct.Job, error) {
	if !idPattern.MatchString(id) {
		var err error
		id, err = cluster.ExtractUUID(id)
		if err != nil {
			return nil, ErrNotFound
		}
	}
	row := r.db.QueryRow("job_select", id)
	return scanJob(row)
}
Beispiel #2
0
func (s *Scheduler) handleActiveJob(activeJob *host.ActiveJob) *Job {
	hostJob := activeJob.Job
	appID := hostJob.Metadata["flynn-controller.app"]
	releaseID := hostJob.Metadata["flynn-controller.release"]

	// if job has no app metadata, just ignore it
	if appID == "" || releaseID == "" {
		return nil
	}

	jobType := hostJob.Metadata["flynn-controller.type"]

	// lookup the job using the UUID part of the job ID (see the
	// description of Job.ID)
	id, err := cluster.ExtractUUID(hostJob.ID)
	if err != nil {
		// job has invalid ID, ignore (very unexpected)
		return nil
	}
	job, ok := s.jobs[id]
	if !ok {
		// this is the first time we have seen the job so
		// add it to s.jobs
		job = &Job{
			ID:        id,
			Type:      jobType,
			AppID:     appID,
			ReleaseID: releaseID,
			HostID:    activeJob.HostID,
			JobID:     hostJob.ID,
		}
		s.jobs.Add(job)
	}

	job.startedAt = activeJob.StartedAt
	job.metadata = hostJob.Metadata
	job.exitStatus = activeJob.ExitStatus
	job.hostError = activeJob.Error

	s.handleJobStatus(job, activeJob.Status)

	return job
}