Example #1
0
func (jm *JobMap) GetAll(user *Hyades.Person) (jobs []*Hyades.Job, err error) {
	conn, err := sql.Open("sqlite3", "file:"+jm.dbFile+"?_loc=auto&_busy_timeout=60000")
	if err != nil {
		return nil, err
	}
	defer conn.Close()
	log.Println("Getting job for user", user.Username, user.Id)
	res, err := conn.Query("Select * from JOBS where OwnerID = ?", user.Id)
	if err != nil {
		return nil, err
	}
	defer closeQuery(res)

	for res.Next() {
		job := &Hyades.Job{}
		err := res.Scan(&job.Id, &job.OwnerID, &job.Name, &job.JobFolder, &job.Env, &job.ReturnEnv)
		if err != nil {
			log.Println(err)
		}
		log.Println("Job", job.Id, "Belongs to id", job.OwnerID)
		partres, err := conn.Query("Select Id,DispatchTime,FinishTime,TotalTimeDispatched,Done,Dispatched,BeingHandled,FailCount,Error,Status,Command from JOBPARTS where OwnerID = ?", job.Id)
		if err != nil {
			log.Println(err)
		}
		defer closeQuery(partres)
		for partres.Next() {
			var part Hyades.Work

			err := partres.Scan(&part.PartID, &part.DispatchTime, &part.FinishTime, &part.TotalTimeDispatched, &part.Done, &part.Dispatched, &part.BeingHandled, &part.FailCount, &part.Error, &part.Status, &part.Command)
			if err != nil {
				log.Println("partres.Scan", err)
			}

			paramres, err := conn.Query("Select Parameters from Parameters where JOBPARTSID = ?", part.PartID)
			defer closeQuery(paramres)
			for paramres.Next() {
				var param string
				err := paramres.Scan(&param)
				if err != nil {
					log.Println("paramres.Scan", err)
				}
				part.Parameters = append(part.Parameters, param)
			}

		}
		if partres.Err() != nil {
			log.Println(partres.Err())
		}

		jobs = append(jobs, job)
	}

	return jobs, res.Err()
}
Example #2
0
func (jm *JobMap) GetJob(id string) (job *Hyades.Job, err error) {
	conn, err := sql.Open("sqlite3", "file:"+jm.dbFile+"?_loc=auto&_busy_timeout=60000")
	if err != nil {
		return nil, err
	}
	defer conn.Close()
	res, err := conn.Query("Select * from JOBS where ID = ?", id)
	if err != nil {
		return nil, err
	}
	defer closeQuery(res)
	job = new(Hyades.Job)
	if res.Next() {
		res.Scan(&job.Id, &job.OwnerID, &job.Name, &job.JobFolder, &job.Env, &job.ReturnEnv)
	}

	log.Println("JobID", job.Id)

	partres, err := conn.Query("Select Id,DispatchTime,FinishTime,TotalTimeDispatched,Done,Dispatched,BeingHandled,FailCount,Error,Status,Command from JOBPARTS where OwnerID = ?", job.Id)
	if err != nil {
		log.Println(err)
	}
	defer closeQuery(partres)
	for partres.Next() {
		var part *Hyades.Work = Hyades.NewWork(job)

		err := partres.Scan(&part.PartID, &part.DispatchTime, &part.FinishTime, &part.TotalTimeDispatched, &part.Done, &part.Dispatched, &part.BeingHandled, &part.FailCount, &part.Error, &part.Status, &part.Command)
		if err != nil {
			log.Println("partres.Scan", err)
		}

		log.Println("PartId", part.PartID)

		paramres, err := conn.Query("Select Parameters from Parameters where JOBPARTSID = ?", part.PartID)
		defer closeQuery(paramres)
		for paramres.Next() {
			var param string
			err := paramres.Scan(&param)
			if err != nil {
				log.Println("paramres.Scan", err)
			}
			part.Parameters = append(part.Parameters, param)
		}
	}

	if partres.Err() != nil {
		log.Println(partres.Err())
	}

	log.Println("Job has", len(job.Parts), " parts")

	return job, err
}
Example #3
0
func (ws *WorkServer) SaveResult(w *Hyades.Work, res *Hyades.WorkResult) error {
	//Get Job work was part of, Get person Job belonged to and then save under
	//Person.JobFolder\Job.JobID\Work.partID\

	//Save 3 parts
	//Env.zip -- iff len(Env) > 0
	//StdOut.txt
	//ErrOut.txtlogFile

	folder := filepath.Join(ws.dataPath, w.PartOf().JobFolder, w.PartOf().Name+fmt.Sprint(w.PartOf().Id), strconv.Itoa(w.Index()))
	err := os.MkdirAll(folder, os.ModeDir|os.ModePerm)
	if err != nil {
		ws.Log.Println(err)
		return err
	}
	if res.EnvLength > 0 {
		envfile, err := os.Create(filepath.Join(folder, "Env.zip"))
		if err != nil {
			ws.Log.Println(err)
		}
		defer envfile.Close()
		_, err = io.CopyN(envfile, res.GetEnv(), int64(res.EnvLength))
		if err != nil {
			ws.Log.Println(err)
			log.Println("SaveResult", err)
			return err
		}
	}

	stdout, err := os.Create(filepath.Join(folder, "StdOut.txt"))
	if err != nil {
		ws.Log.Println(err)
		return err
	}
	defer stdout.Close()
	stdout.Write(res.StdOutStream)

	errout, err := os.Create(filepath.Join(folder, "ErrOut.txt"))
	if err != nil {
		ws.Log.Println(err)
	}
	defer errout.Close()
	errout.Write(res.ErrOutStream)

	return nil
}
Example #4
0
func (ws *WorkServer) doneWork(work *Hyades.Work, res *Hyades.WorkResult) error {
	err := work.Succeeded()
	if err != nil {
		return err
	}
	work.SetStatus("Saving work")
	err = ws.SaveResult(work, res)
	if err != nil {
		return err
	}

	work.SetStatus("Work done")

	//work.PartOf().Save(ws.db.session)
	return nil
}
Example #5
0
func (ws *WorkServer) retryWork(work *Hyades.Work, err string) {
	work.Failed()
	work.SetStatus("In Queue after error " + err)
}