Ejemplo n.º 1
0
func (ts *dttServer) GetImage() (*dttrpc.Job, error) {

	// get random image job from server
	sjobs, err := ts.GetAllSjobs()
	if err != nil {
		return nil, err
	}

	sid := sjobs[rand.Intn(len(sjobs))]

	jobs, jerr := ts.GetSjobJobs(sid)
	if jerr != nil {
		return nil, jerr
	}
	jid := jobs[rand.Intn(len(jobs))].Jid

	imgLoc, err := ts.Lstore.Get(LOC_PREFIX + makeImgJobKey(sid, jid))

	if err != nil {
		return nil, err
	}

	job := new(dttrpc.Job)
	job.Sid = sid
	job.Jid = jid
	job.Loc = imgLoc

	return job, nil

}
Ejemplo n.º 2
0
func (ts *dttServer) GetSjobJobs(sjid int) ([]*dttrpc.Job, error) {

	jidList, err := ts.GetJobList(sjid)

	if err != nil {
		return nil, err
	}

	transcripts := make([]*dttrpc.Job, len(jidList), len(jidList))

	for i, v := range jidList {
		loc, imgerr := ts.Lstore.Get(LOC_PREFIX + makeImgJobKey(sjid, v))
		if imgerr != nil {
			return nil, imgerr
		}

		trans, transerr := ts.Lstore.Get(TRANS_PREFIX + makeImgJobKey(sjid, v))
		if transerr != nil && transerr.Error() != "KeyNotFound" {
			return nil, transerr
		}

		job := new(dttrpc.Job)
		job.Sid = sjid
		job.Jid = v
		job.Loc = loc
		job.Transcript = trans

		transcripts[i] = job
	}

	return transcripts, nil
}