Commit 8c6714c2 authored by Kyle Clarke's avatar Kyle Clarke 💬

Name change from JobRunner to Runner, job is superfluous in this sense.

parent a61cd4de
......@@ -27,10 +27,10 @@ const (
)
// Runners are a map of all job runners key'd on JobID.
type Runners map[JobID]*jobRunner
type Runners map[JobID]*runner
// JobRunner struct to contain meta data and the runner task.
type jobRunner struct {
// Runner struct to contain meta data and the runner task.
type runner struct {
completed time.Time
err error
callFn reflect.Value
......@@ -44,7 +44,7 @@ type jobRunner struct {
// Given a jobber, use reflection to create the func and func params to
// call inside doRun.
func initRunner(j *Job) (*jobRunner, error) {
func initRunner(j *Job) (*runner, error) {
// Be sure we can parse the func and func params
f := j.Fn
rt := reflect.TypeOf(f)
......@@ -63,51 +63,51 @@ func initRunner(j *Job) (*jobRunner, error) {
in[k] = reflect.ValueOf(fnParam)
}
jr := NewJobRunner()
jr := NewRunner()
jr.job = j
jr.callFn = Fn
jr.callFnParams = in
return jr, nil
}
// NewJobRunner will return a pointer to a new jobRunner instance.
func NewJobRunner() *jobRunner {
return &jobRunner{}
// NewRunner will return a pointer to a new runner instance.
func NewRunner() *runner {
return &runner{}
}
// CanBegin will return true if a begin time is set and is older than the current time.
func (r *jobRunner) CanBegin() bool {
func (r *runner) CanBegin() bool {
return r.job.Begins.IsZero() || r.job.Begins.Before(time.Now())
}
// CapBreached will return true if this Job has a Cap and it is over the running count.
func (r *jobRunner) CapBreached() bool {
func (r *runner) CapBreached() bool {
return (r.job.Cap != 0 && r.runningCount > r.job.Cap)
}
// Expired will return true if an expiration time is set and is before now.
func (r *jobRunner) Expired() bool {
func (r *runner) Expired() bool {
return (!r.job.Expires.IsZero() && r.job.Expires.Before(time.Now()))
}
// Run invokes do() on this job runner instance via a go routine.
func (r *jobRunner) Run() {
func (r *runner) Run() {
go do(r)
}
// Stop will set this runners stop flag. This does not ensure that the runner job will
// stop when called. It does guarantee that the next "Every" invocation will stop.
func (r *jobRunner) Stop() {
func (r *runner) Stop() {
r.stop = true
}
// Stopped returns this runners current stop flag value.
func (r *jobRunner) Stopped() bool {
func (r *runner) Stopped() bool {
return r.stop
}
// do is called via Run in a go routine.
func do(r *jobRunner) {
func do(r *runner) {
safety := uint64(0)
Every := time.NewTicker(r.job.Every)
defer func() {
......@@ -171,8 +171,8 @@ func do(r *jobRunner) {
}
}
// JobRunnerInfo is a struct that contains runner instance information.
type JobRunnerInfo struct {
// RunnerInfo is a struct that contains runner instance information.
type RunnerInfo struct {
Status string
RunningCount uint64
CompletedAt time.Time
......@@ -180,9 +180,9 @@ type JobRunnerInfo struct {
Stopped bool
}
// Info will return a new populated JobRunnerInfo struct. Reference, not a pointer.
func (r *jobRunner) Info() JobRunnerInfo {
return JobRunnerInfo{
// Info will return a new populated RunnerInfo struct. Reference, not a pointer.
func (r *runner) Info() RunnerInfo {
return RunnerInfo{
Status: r.status,
RunningCount: r.runningCount,
CompletedAt: r.completed,
......@@ -192,16 +192,16 @@ func (r *jobRunner) Info() JobRunnerInfo {
}
// IsCompleted will return true if a completed time is set.
func (i JobRunnerInfo) IsCompleted() bool {
func (i RunnerInfo) IsCompleted() bool {
return !i.CompletedAt.IsZero()
}
// IsPending will return true if not complete and not started.
func (i JobRunnerInfo) IsPending() bool {
func (i RunnerInfo) IsPending() bool {
return (!i.IsCompleted() && i.StartedAt.IsZero())
}
// IsRunning will return true if not complete and started.
func (i JobRunnerInfo) IsRunning() bool {
func (i RunnerInfo) IsRunning() bool {
return (!i.IsCompleted() && !i.StartedAt.IsZero())
}
......@@ -29,7 +29,7 @@ func Test_initRunner(t *testing.T) {
}
}
func TestJobRunner_CanBegin(t *testing.T) {
func TestRunner_CanBegin(t *testing.T) {
Reset()
j := newSimpleJob()
j.Begins = time.Now().Add(time.Minute)
......@@ -52,7 +52,7 @@ func TestJobRunner_CanBegin(t *testing.T) {
}
}
func TestJobRunner_CapBreached(t *testing.T) {
func TestRunner_CapBreached(t *testing.T) {
Reset()
j := newSimpleJob()
j.Cap = 0
......@@ -81,7 +81,7 @@ func TestJobRunner_CapBreached(t *testing.T) {
}
}
func TestJobRunner_Expired(t *testing.T) {
func TestRunner_Expired(t *testing.T) {
Reset()
j := newSimpleJob()
......@@ -106,7 +106,7 @@ func TestJobRunner_Expired(t *testing.T) {
}
}
func TestJobRunner_Stop(t *testing.T) {
func TestRunner_Stop(t *testing.T) {
Reset()
j := newSimpleJob()
s := DefaultSchedule()
......@@ -121,15 +121,15 @@ func TestJobRunner_Stop(t *testing.T) {
}
}
func TestJobRunner_Stopped(t *testing.T) {
r := NewJobRunner()
func TestRunner_Stopped(t *testing.T) {
r := NewRunner()
if r.Stopped() {
t.Error("Stopped should be false by default.")
}
}
func TestJobRunnerInfo_IsPending(t *testing.T) {
i := JobRunnerInfo{}
func TestRunnerInfo_IsPending(t *testing.T) {
i := RunnerInfo{}
if !i.IsPending() {
t.Error("No completed and zero start time should be pending.")
}
......
......@@ -175,8 +175,8 @@ func (s *Schedule) doPurge(before time.Duration) {
}
}
// Find will attempt to find and return a JobRunner instance on this schedule. Returns error on not found.
func (s *Schedule) Find(ID JobID) (*jobRunner, error) {
// Find will attempt to find and return a Runner instance on this schedule. Returns error on not found.
func (s *Schedule) Find(ID JobID) (*runner, error) {
j, ok := s.runners[ID]
if ok {
return j, nil
......
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