Esempio n. 1
0
func (j *Job) ControllerJob() *ct.Job {
	job := &ct.Job{
		ID:        j.JobID,
		UUID:      j.ID,
		HostID:    j.HostID,
		AppID:     j.AppID,
		ReleaseID: j.ReleaseID,
		Type:      j.Type,
		Meta:      utils.JobMetaFromMetadata(j.metadata),
		HostError: j.hostError,
		RunAt:     j.runAt,
	}

	switch j.state {
	case JobStatePending:
		job.State = ct.JobStatePending
	case JobStateStarting:
		job.State = ct.JobStateStarting
	case JobStateRunning:
		job.State = ct.JobStateUp
	case JobStateStopped:
		job.State = ct.JobStateDown
	}

	if j.exitStatus != nil {
		job.ExitStatus = typeconv.Int32Ptr(int32(*j.exitStatus))
	}
	if j.restarts > 0 {
		job.Restarts = typeconv.Int32Ptr(int32(j.restarts))
	}

	return job
}
Esempio n. 2
0
func (s *Scheduler) handleActiveJob(activeJob *host.ActiveJob) (*Job, error) {
	job := activeJob.Job
	appID := job.Metadata["flynn-controller.app"]
	appName := job.Metadata["flynn-controller.app_name"]
	releaseID := job.Metadata["flynn-controller.release"]
	jobType := job.Metadata["flynn-controller.type"]

	if appID == "" || releaseID == "" {
		return nil, errors.New("ignoring job due to lack of appID or releaseID")
	}
	log := logger.New("fn", "handleActiveJob", "job.id", job.ID, "app.id", appID, "release.id", releaseID, "job.type", jobType)

	var j *Job
	var err error
	j = s.jobs[job.ID]
	if j == nil {
		log.Info("creating new job")
		j = NewJob(nil, appID, releaseID, jobType, activeJob.HostID, job.ID)
	}
	if j.Formation == nil {
		log.Info("looking up formation")
		f := s.formations.Get(appID, releaseID)
		if f == nil {
			log.Info("job is from new formation, getting formation from controller")
			var cf *ct.Formation
			cf, err = s.GetFormation(appID, releaseID)
			if err != nil {
				log.Error("error getting formation", "err", err)
			} else {
				f, err = s.updateFormation(cf)
				if err != nil {
					log.Error("error updating formation", "err", err)
				}
			}
		}
		j.Formation = f
	}
	j.startedAt = activeJob.StartedAt
	if s.SaveJob(j, appName, activeJob.Status, utils.JobMetaFromMetadata(job.Metadata)) {
		log.Info("saved job to controller")
	}

	return j, err
}