Commit 88e953a7 authored by Kyle Clarke's avatar Kyle Clarke 💬

Updated readme with public struct changes. Prefixed existing bool methods with "Is"

parent 4c605304
Pipeline #5471452 passed with stages
in 36 seconds
......@@ -6,9 +6,7 @@ ___
[logo]: http://i3.mirror.co.uk/incoming/article1772857.ece/ALTERNATES/s615b/It's%20Kevin.jpg
[![Build Status](https://gitlab.com/kylehqcom/kevin/badges/master/build.svg)](https://gitlab.com/kylehqcom/kevin/commits/master)
[![Go report card](https://goreportcard.com/badge/gitlab.com/kylehqcom/kevin)](https://goreportcard.com/report/gitlab.com/kylehqcom/kevin)
[![Build Status](https://gitlab.com/kylehqcom/kevin/badges/master/build.svg)](https://gitlab.com/kylehqcom/kevin/commits/master) ![](https://codeship.com/projects/e9837a40-9fe1-0134-4a7e-4225655adfa5/status?branch=master) [![Go report card](https://goreportcard.com/badge/gitlab.com/kylehqcom/kevin)](https://goreportcard.com/report/gitlab.com/kylehqcom/kevin)
Kevin is an in memory non persistent scheduler written in Golang that simplifies
handling repeating method calls. Kevin allows you to
......@@ -39,17 +37,16 @@ JobID, _ := kevin.DefaultSchedule().Run(&Job{
})
// Some time later we check the status.
runner, _ := kevin.DefaultSchedule().FindByJobID(JobID)
i := runner.Info()
if i.IsRunning() {
job, _ := kevin.DefaultSchedule().FindByJobID(JobID)
if job.IsRunning() {
// All is well
fmt.Println(fmt.Sprintf("Simple has run %d times.", i.RunningCount))
fmt.Println(fmt.Sprintf("Simple has run %d times.", job.RunningCount))
} else {
// Alert
}
// Since we haven't set an "Expires" value, let's stop manually.
runner.Stop()
job.Stop()
```
For full reference documentation, go to [![GoDoc](https://godoc.org/gitlab.com/kylehqcom/kevin?status.svg)](https://godoc.org/gitlab.com/kylehqcom/kevin)
......
......@@ -112,6 +112,11 @@ func (r *Runner) IsCompleted() bool {
return !r.Completed.IsZero()
}
// IsExpired will return true if an expiration time is set and is before now.
func (r *Runner) IsExpired() bool {
return (!r.job.Expires.IsZero() && r.job.Expires.Before(time.Now()))
}
// IsPending will return true if not complete and not started.
func (r *Runner) IsPending() bool {
return (!r.IsCompleted() && r.Started.IsZero())
......@@ -122,14 +127,14 @@ func (r *Runner) IsRunning() bool {
return (!r.IsCompleted() && !r.Started.IsZero())
}
// IsStopping will return true if not complete but stop flag true.
func (r *Runner) IsStopping() bool {
return (!r.IsCompleted() && r.Stopped())
// Stopped returns this runners current stop flag value.
func (r *Runner) IsStopped() bool {
return r.stop
}
// Expired will return true if an expiration time is set and is before now.
func (r *Runner) Expired() bool {
return (!r.job.Expires.IsZero() && r.job.Expires.Before(time.Now()))
// IsStopping will return true if not complete but stop flag true.
func (r *Runner) IsStopping() bool {
return (!r.IsCompleted() && r.IsStopped())
}
// Run invokes do() on this job runner instance via a go routine.
......@@ -143,11 +148,6 @@ func (r *Runner) Stop() {
r.stop = true
}
// Stopped returns this runners current stop flag value.
func (r *Runner) Stopped() bool {
return r.stop
}
// do is called via Run in a go routine.
func do(r *Runner) {
safety := uint64(0)
......@@ -173,7 +173,7 @@ func do(r *Runner) {
}
// Also check for an expiration time.
if r.Expired() {
if r.IsExpired() {
r.Status = StatusExpired
break
}
......
......@@ -89,7 +89,7 @@ func TestRunner_CapBreached(t *testing.T) {
}
}
func TestRunner_Expired(t *testing.T) {
func TestRunner_IsExpired(t *testing.T) {
Reset()
j := newSimpleJob()
......@@ -99,17 +99,17 @@ func TestRunner_Expired(t *testing.T) {
s.Add(j)
r, _ := s.FindByJobID(j.ID)
if r.Expired() {
if r.IsExpired() {
t.Error("Expired should be false as zero expire time assigned to job.")
}
j.Expires = time.Now().Add(time.Minute)
if r.Expired() {
if r.IsExpired() {
t.Error("Expired should be false as expiration one minute from now.")
}
j.Expires = time.Now().Add(-1 * time.Minute)
if !r.Expired() {
if !r.IsExpired() {
t.Error("Expired should be true as expiration one minute in past.")
}
}
......@@ -120,18 +120,18 @@ func TestRunner_Stop(t *testing.T) {
s := DefaultSchedule()
s.Add(j)
r, _ := s.FindByJobID(j.ID)
if r.Stopped() {
if r.IsStopped() {
t.Error("A job should not be stopped by default.")
}
r.Stop()
if !r.Stopped() {
if !r.IsStopped() {
t.Error("A job should be stopped after stop() call.")
}
}
func TestRunner_Stopped(t *testing.T) {
func TestRunner_IsStopped(t *testing.T) {
r := Runner{}
if r.Stopped() {
if r.IsStopped() {
t.Error("Stopped should be false by default.")
}
}
......
......@@ -451,14 +451,14 @@ func TestSchedule_Stop(t *testing.T) {
t.Error("We have slept so job should be running.")
}
if r.Stopped() {
if r.IsStopped() {
t.Error("Runner should not have a stop flag of true.")
}
s.Stop(j.ID)
time.Sleep(300 * time.Millisecond)
if !r.Stopped() {
if !r.IsStopped() {
t.Error("Runner should have a stop flag of true.")
}
......
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