Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2017 The LUCI Authors. All rights reserved. | |
| 2 // Use of this source code is governed under the Apache License, Version 2.0 | |
| 3 // that can be found in the LICENSE file. | |
| 4 | |
| 5 package presentation | |
| 6 | |
| 7 import ( | |
| 8 "fmt" | |
| 9 | |
| 10 "github.com/luci/luci-go/scheduler/appengine/catalog" | |
| 11 "github.com/luci/luci-go/scheduler/appengine/engine" | |
| 12 "github.com/luci/luci-go/scheduler/appengine/task" | |
| 13 ) | |
| 14 | |
| 15 // PublicStateKind defines state of the job which is exposed in UI and API | |
| 16 // instead of internal engine.StateKind which is kept as an implementation | |
| 17 // detail. | |
| 18 type PublicStateKind string | |
| 19 | |
| 20 const ( | |
| 21 PublicStateDisabled PublicStateKind = "DISABLED" | |
| 22 PublicStateOverrun PublicStateKind = "OVERRUN" | |
| 23 PublicStatePaused PublicStateKind = "PAUSED" | |
| 24 PublicStateRetrying PublicStateKind = "RETRYING" | |
| 25 PublicStateRunning PublicStateKind = "RUNNING" | |
| 26 PublicStateScheduled PublicStateKind = "SCHEDULED" | |
| 27 PublicStateStarting PublicStateKind = "STARTING" | |
| 28 PublicStateSuspended PublicStateKind = "SUSPENDED" | |
| 29 PublicStateWaiting PublicStateKind = "WAITING" | |
| 30 ) | |
| 31 | |
| 32 // GetPublicStateKind returns user-friendly state and labelClass. | |
| 33 func GetPublicStateKind(j *engine.Job, traits task.Traits) PublicStateKind { | |
| 34 switch { | |
| 35 case j.State.IsRetrying(): | |
| 36 // Retries happen when invocation fails to launch (move from "ST ARTING" to | |
| 37 // "RUNNING" state). Such invocation is retried (as new invocati on). When | |
| 38 // a retry is enqueued, we display the job state as "RETRYING" ( even though | |
| 39 // technically it is still "QUEUED"). | |
| 40 return PublicStateRetrying | |
| 41 case !traits.Multistage && j.State.InvocationID != 0: | |
| 42 // The job has an active invocation and the engine has called La unchTask for | |
| 43 // it already. Jobs with Multistage == false trait do all their work in | |
| 44 // LaunchTask, so we display them as "RUNNING" (instead of "STAR TING"). | |
| 45 return PublicStateRunning | |
| 46 case j.State.State == engine.JobStateQueued: | |
| 47 // An invocation has been added to the task queue, and the engin e hasn't | |
| 48 // attempted to launch it yet. | |
| 49 return PublicStateStarting | |
| 50 case j.State.State == engine.JobStateSlowQueue: | |
| 51 // Job invocation is still in the task queue, but new invocation should be | |
| 52 // starting now (so the queue is lagging for some reason). | |
| 53 return PublicStateStarting | |
| 54 case j.Paused && j.State.State == engine.JobStateSuspended: | |
| 55 // Paused jobs don't have a schedule, so they are always in "SUS PENDED" | |
| 56 // state. Make it clearer that they are just paused. This applie s to both | |
| 57 // triggered and periodic jobs. | |
| 58 return PublicStatePaused | |
| 59 case j.State.State == engine.JobStateSuspended && j.Flavor == catalog.Jo bFlavorTriggered: | |
| 60 // Triggered jobs don't run on a schedule. They are in "SUSPENDE D" state | |
| 61 // between triggering events, rename it to "WAITING" for clarity . | |
| 62 return PublicStateWaiting | |
| 63 default: | |
| 64 if r, ok := map[engine.StateKind]PublicStateKind{ | |
|
Vadim Sh.
2017/06/20 17:48:54
please make this map package-level global var
tandrii(chromium)
2017/06/20 19:48:36
Done.
| |
| 65 engine.JobStateDisabled: PublicStateDisabled, | |
| 66 engine.JobStateScheduled: PublicStateScheduled, | |
| 67 engine.JobStateSuspended: PublicStateSuspended, | |
| 68 engine.JobStateRunning: PublicStateRunning, | |
| 69 engine.JobStateOverrun: PublicStateOverrun, | |
| 70 }[j.State.State]; !ok { | |
| 71 panic(fmt.Errorf("unknown state: %q", j.State.State)) | |
| 72 } else { | |
| 73 return r | |
| 74 } | |
| 75 } | |
| 76 } | |
| OLD | NEW |