Commit 39a8cb07 authored by Kyle Clarke's avatar Kyle Clarke 💬

Methods should return public struct, therefore Schedule is now public.

parent ec84b9f1
Pipeline #5407023 passed with stages
in 28 seconds
......@@ -54,7 +54,7 @@ type schedulePool struct {
}
// schedules are a string map of Schedulers
type schedules map[string]*schedule
type schedules map[string]*Schedule
// SchedulesInfo represents information about all Schedulers assigned to the schedule pool.
type SchedulesInfo struct {
......@@ -71,7 +71,7 @@ func All() schedules {
}
// ByName will attempt to return by name a Scheduler instance from the schedule pool.
func ByName(name string) (*schedule, error) {
func ByName(name string) (*Schedule, error) {
v, ok := pool.schedules[name]
if ok {
return v, nil
......@@ -81,7 +81,7 @@ func ByName(name string) (*schedule, error) {
}
// DefaultSchedule will return the default schedule from the schedule pool.
func DefaultSchedule() *schedule {
func DefaultSchedule() *Schedule {
s, err := ByName(DefaultName)
if err != nil {
sc := NewScheduleConfig()
......
......@@ -6,7 +6,7 @@ import (
)
// Schedule is the default struct that houses job runners.
type schedule struct {
type Schedule struct {
config ScheduleConfig
runners Runners
purgeTicker *time.Ticker
......@@ -57,7 +57,7 @@ type Job struct {
ID JobID
// As a schedule can dig in to get a job runner, a job should be able to dig out to it's schedule.
schedule *schedule
schedule *Schedule
}
// AddFnParams is a convenience method to add params to the Job instance.
......@@ -66,14 +66,14 @@ func (j *Job) AddFnParams(params ...interface{}) {
}
// NewSchedule will return a new Scheduler instance. It expects ScheduleConfig.
func NewSchedule(sc ScheduleConfig) (*schedule, error) {
func NewSchedule(sc ScheduleConfig) (*Schedule, error) {
if "" == sc.Name {
return nil, ErrScheduleEmptyName
}
// Create a new schedule, add to the schedulePool.
schedule := &schedule{
schedule := &Schedule{
runners: make(Runners),
config: sc,
}
......@@ -104,7 +104,7 @@ func NewScheduleConfig() ScheduleConfig {
// Add will attempt to Add a new Job to the current schedule. It will return an error on
// a duplicate JobID found, or an Every duration value of zero.
func (s *schedule) Add(j *Job) (JobID, error) {
func (s *Schedule) Add(j *Job) (JobID, error) {
if "" == j.ID {
j.ID = GenerateID()
}
......@@ -137,7 +137,7 @@ func (s *schedule) Add(j *Job) (JobID, error) {
}
// Run will Add and then Run a job against a runner. Refer to Add for errors returned.
func (s *schedule) Run(j *Job) (JobID, error) {
func (s *Schedule) Run(j *Job) (JobID, error) {
ID, err := s.Add(j)
if err != nil {
return ID, err
......@@ -149,7 +149,7 @@ func (s *schedule) Run(j *Job) (JobID, error) {
// AutoPurge will setup a ticker to purge completed jobs based on this schedules
// PurgeAfter config value. Passing in a zero duration will stop the ticker.
func (s *schedule) AutoPurge(pollEvery time.Duration) {
func (s *Schedule) AutoPurge(pollEvery time.Duration) {
// Always call stop on any AutoPurge call to ensure no goroutine leaks.
if nil != s.purgeTicker {
s.purgeTicker.Stop()
......@@ -157,7 +157,7 @@ func (s *schedule) AutoPurge(pollEvery time.Duration) {
if 0 != pollEvery.Nanoseconds() {
s.purgeTicker = time.NewTicker(pollEvery)
go func(s *schedule) {
go func(s *Schedule) {
for range s.purgeTicker.C {
s.doPurge(s.config.PurgeAfter)
}
......@@ -166,7 +166,7 @@ func (s *schedule) AutoPurge(pollEvery time.Duration) {
}
// doPurge is responsible for the removal of completed job runners from a schedule.
func (s *schedule) doPurge(before time.Duration) {
func (s *Schedule) doPurge(before time.Duration) {
if !s.IsEmpty() {
d := time.Now().UTC().Add(-1 * before)
for _, r := range s.runners {
......@@ -178,19 +178,19 @@ func (s *schedule) doPurge(before time.Duration) {
}
// All will return all Job runners assigned to the schedule instance.
func (s *schedule) All() Runners {
func (s *Schedule) All() Runners {
return s.runners
}
// Find will attempt to find and return a Runner instance on this schedule by a common String.
// Internally Kevin uses a JobID type so this Find method is used as a convenience for your
// common string references. Returns error on not found.
func (s *schedule) Find(ID string) (*runner, error) {
func (s *Schedule) Find(ID string) (*runner, error) {
return s.FindByJobID(JobID(ID))
}
// Find will attempt to find and return a Runner instance on this schedule by JobID. Returns error on not found.
func (s *schedule) FindByJobID(ID JobID) (*runner, error) {
func (s *Schedule) FindByJobID(ID JobID) (*runner, error) {
j, ok := s.runners[ID]
if ok {
return j, nil
......@@ -200,7 +200,7 @@ func (s *schedule) FindByJobID(ID JobID) (*runner, error) {
}
// Info returns generic schedule info about this schedule instance.
func (s *schedule) Info() ScheduleInfo {
func (s *Schedule) Info() ScheduleInfo {
return ScheduleInfo{
Name: s.Name(),
Count: int64(len(s.runners)),
......@@ -208,24 +208,24 @@ func (s *schedule) Info() ScheduleInfo {
}
// IsEmpty will return true is there are no runners assigned against this schedule instance.
func (s *schedule) IsEmpty() bool {
func (s *Schedule) IsEmpty() bool {
return 0 == len(s.runners)
}
// Name will return the schedule name.
func (s *schedule) Name() string {
func (s *Schedule) Name() string {
return s.config.Name
}
// Purge will remove completed jobs from this schedule instance older than the
// before duration param you pass.
func (s *schedule) Purge(before time.Duration) error {
func (s *Schedule) Purge(before time.Duration) error {
s.doPurge(before)
return nil
}
// Remove will first attempt to stop the job and then remove from this schedule.
func (s *schedule) Remove(ID JobID) error {
func (s *Schedule) Remove(ID JobID) error {
err := s.Stop(ID)
if err != nil {
return err
......@@ -236,7 +236,7 @@ func (s *schedule) Remove(ID JobID) error {
}
// Reset will attempt to stop and remove ALL jobs from this schedule.
func (s *schedule) Reset() error {
func (s *Schedule) Reset() error {
for _, r := range s.runners {
err := s.Remove(r.job.ID)
if err != nil {
......@@ -247,7 +247,7 @@ func (s *schedule) Reset() error {
}
// Stop will attempt to stop the execution on the next job runner from this schedule.
func (s *schedule) Stop(ID JobID) error {
func (s *Schedule) Stop(ID JobID) error {
r, err := s.FindByJobID(ID)
if err != nil {
return err
......
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