예제 #1
0
파일: main.go 프로젝트: joshie/lochness
func startJob(task *jobqueue.Task, agent *lochness.MistifyAgent) error {
	job := task.Job

	var err error
	var jobID string
	switch job.Action {
	case "fetch":
		jobID, err = agent.FetchImage(task.Guest.ID)
	case "create":
		jobID, err = agent.CreateGuest(task.Guest.ID)
	case "delete":
		jobID, err = agent.DeleteGuest(task.Guest.ID)
	default:
		if _, ok := config.ValidActions[job.Action]; !ok {
			return errors.New("invalid action")
		}
		jobID, err = agent.GuestAction(task.Guest.ID, job.Action)
	}

	if err != nil {
		return err
	}
	task.Job.RemoteID = jobID
	_ = updateJobStatus(task, jobqueue.JobStatusWorking, nil)
	return nil
}
예제 #2
0
파일: main.go 프로젝트: joshie/lochness
func checkWorkingJob(task *jobqueue.Task, agent *lochness.MistifyAgent) (bool, error) {
	done, err := agent.CheckJobStatus(task.Job.Action, task.Guest.ID, task.Job.RemoteID)
	if err == nil && done && task.Job.Action == "fetch" {
		task.Job.Action = "create"
		task.Job.RemoteID = ""
		task.Job.Status = jobqueue.JobStatusNew

		done = false
		// Save Job Status
		if err := task.Job.Save(24 * time.Hour); err != nil {
			log.WithFields(log.Fields{
				"task":  task,
				"error": err,
			}).Error("unable to save")
			return done, err
		}
	}

	return done, err
}