本文整理匯總了Golang中github.com/HeinOldewage/Hyades.Work類的典型用法代碼示例。如果您正苦於以下問題:Golang Work類的具體用法?Golang Work怎麽用?Golang Work使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了Work類的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: GetAll
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(¶m)
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()
}
示例2: GetJob
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(¶m)
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
}
示例3: SaveResult
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
}
示例4: doneWork
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
}
示例5: retryWork
func (ws *WorkServer) retryWork(work *Hyades.Work, err string) {
work.Failed()
work.SetStatus("In Queue after error " + err)
}