Commit 5a2f8bc9 authored by Kyle Clarke's avatar Kyle Clarke 💬

Added new stopping status along with test cases to confirm.

parent a3456975
Pipeline #4950224 passed with stage
in 33 seconds
......@@ -13,6 +13,11 @@ const (
// StatusRunning is a simple string representation of a running status
StatusRunning = "running"
// StatusStopping is defined by the stop flag being true, but the ticker not yet invoked to check the
// flag. This occurs because the stop flag is called from outside a ticker loop. The ticker checks
// the stop flag value on each tick.
StatusStopping = "stopping"
// StatusStopped is a simple string representation of a stopped status
StatusStopped = "stopped"
......@@ -190,14 +195,8 @@ type RunnerInfo struct {
// Info will return a new populated RunnerInfo struct. Reference, not a pointer.
func (r *runner) Info() RunnerInfo {
status := r.status
if "" == status {
status = StatusPending
}
return RunnerInfo{
ri := RunnerInfo{
ID: string(r.job.ID),
Status: status,
Every: r.job.Every.Seconds(),
Cap: r.job.Cap,
RunningCount: r.runningCount,
......@@ -205,6 +204,23 @@ func (r *runner) Info() RunnerInfo {
StartedAt: r.started,
Stopped: r.stop,
}
var status string
switch true {
case ri.IsPending():
status = StatusPending
break
case ri.IsStopping():
status = StatusStopping
break
default:
status = r.status
}
ri.Status = status
return ri
}
// IsCompleted will return true if a completed time is not zero and therefore complete.
......@@ -221,3 +237,8 @@ func (i RunnerInfo) IsPending() bool {
func (i RunnerInfo) IsRunning() bool {
return (!i.IsCompleted() && !i.StartedAt.IsZero())
}
// IsStopping will return true if not complete but stop flag true.
func (i RunnerInfo) IsStopping() bool {
return (!i.IsCompleted() && i.Stopped)
}
......@@ -142,3 +142,17 @@ func TestRunnerInfo_IsPending(t *testing.T) {
t.Error("No completed and zero start time should be pending.")
}
}
func TestRunnerInfo_IsRunning(t *testing.T) {
i := RunnerInfo{StartedAt: time.Now()}
if !i.IsRunning() {
t.Error("No completed and a start time should be running.")
}
}
func TestRunnerInfo_IsStopping(t *testing.T) {
i := RunnerInfo{Stopped: true}
if !i.IsStopping() {
t.Error("Zero completed time and stopped flag should be stopping.")
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment