//Unmarshal initialise the current job with values from the format.Job message func (j *job) Unmarshal(f *format.Job) error { id := f.Id j.name = id.GetName() j.remote = id.GetRemote() j.branch = id.GetBranch() if err := j.refresh.Unmarshal(f.GetRefresh()); err != nil { return err } if err := j.build.Unmarshal(f.GetBuild()); err != nil { return err } return nil }
func Status(j *format.Job) string { var zero, rstart, rend, bstart, bend time.Time rstart = time.Unix(j.Refresh.GetStart(), 0) rend = time.Unix(j.Refresh.GetEnd(), 0) bstart = time.Unix(j.Build.GetStart(), 0) bend = time.Unix(j.Build.GetEnd(), 0) switch { case zero.Equal(rstart) || zero.Equal(bstart) || rstart.After(rend) || bstart.After(bend): return "running" case j.GetRefresh().GetErrcode() == 0 && j.GetBuild().GetErrcode() == 0: return "success" default: return "failed" } }