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

Altered purgeBefore to a better reading purgeAfter

parent 7153563f
......@@ -58,7 +58,7 @@ create your own custom schedules call
```
c := kevin.ScheduleConfig{
Name: "custom",
PurgeBefore: OPTIONAL time.Duration
PurgeAfter: OPTIONAL time.Duration
PurgePoll: OPTIONAL time.Duration
})
s, err := kevin.NewSchedule(c)
......@@ -69,8 +69,8 @@ found. Names **are** case sensitive.
The optional purge fields help define an auto purger created on your new schedule. If
left to the defaults, on every hour the schedule will be purged, removing all
***completed*** job runners that are older than 24 hours. Alter the ***PurgeBefore***
time.Duration to purge older/newer runners.
***completed*** job runners that are older than 24 hours. Alter the ***PurgeAfter***
time.Duration purge completed runners sooner/later.
Don't want to purge anything? That's no problem! Just pass a zero duration as your
***PurgePoll*** value.
......
......@@ -19,8 +19,8 @@ const (
// DefaultName is the default name used this pools default schedule.
DefaultName = "default"
// DefaultPurgeBefore is the duration used to auto purge schedules.
DefaultPurgeBefore = 24 * time.Hour
// DefaultPurgeAfter is the duration used to remove job runners with a completed time after this value.
DefaultPurgeAfter = 24 * time.Hour
// DefaultPurgePoll is the duration used to auto purge schedules.
DefaultPurgePoll = time.Hour
......@@ -30,7 +30,7 @@ var pool *schedulePool
func init() {
pool = &schedulePool{
schedules: make(schedules),
defaultPurgeBefore: DefaultPurgeBefore,
defaultPurgeAfter: DefaultPurgeAfter,
defaultPurgePoll: DefaultPurgePoll,
}
......@@ -44,7 +44,7 @@ type schedulePool struct {
schedules schedules
// Set the default purge after, completed jobs after this time are purged.
defaultPurgeBefore time.Duration
defaultPurgeAfter time.Duration
// Set the default purge polling interval on this pool.
defaultPurgePoll time.Duration
......@@ -56,7 +56,7 @@ type schedules map[string]*schedule
// SchedulesInfo represents information about all Schedulers assigned to the schedule pool.
type SchedulesInfo struct {
JobCount int64
PurgeBefore time.Duration
PurgeAfter time.Duration
PurgePoll time.Duration
ScheduleCount int64
Schedules map[string]ScheduleInfo
......@@ -93,7 +93,7 @@ func DefaultSchedule() *schedule {
func Info() SchedulesInfo {
c := SchedulesInfo{
Schedules: make(map[string]ScheduleInfo),
PurgeBefore: pool.defaultPurgeBefore,
PurgeAfter: pool.defaultPurgeAfter,
PurgePoll: pool.defaultPurgePoll,
}
......
......@@ -18,7 +18,11 @@ type schedule struct {
// ScheduleConfig are used to create new Schedulers.
type ScheduleConfig struct {
Name string
PurgeBefore time.Duration
// PurgeAfter vlue used to purge job runners that have a completed time older than Now plus this duration.
PurgeAfter time.Duration
// PurgePoll will poll the schedule pool to purge completed jobs. A zero value will not poll. Refer DefaultPurgePoll.
PurgePoll time.Duration
}
......@@ -95,7 +99,7 @@ func NewSchedule(sc ScheduleConfig) (*schedule, error) {
// NewScheduleConfig will create and return new ScheduleConfig pointer.
func NewScheduleConfig() ScheduleConfig {
return ScheduleConfig{
PurgeBefore: pool.defaultPurgeBefore,
PurgeAfter: pool.defaultPurgeAfter,
PurgePoll: pool.defaultPurgePoll,
}
}
......@@ -147,7 +151,7 @@ func (s *schedule) Run(j *Job) (JobID, error) {
}
// AutoPurge will setup a ticker to purge completed jobs based on this schedules
// PurgeBefore config value. Passing in a zero duration will stop the ticker.
// PurgeAfter config value. Passing in a zero duration will stop the ticker.
func (s *schedule) AutoPurge(pollEvery time.Duration) {
if pollEvery.Nanoseconds() == 0 {
if nil != s.purgeTicker {
......@@ -157,7 +161,7 @@ func (s *schedule) AutoPurge(pollEvery time.Duration) {
s.purgeTicker = time.NewTicker(pollEvery)
go func(s *schedule) {
for range s.purgeTicker.C {
s.doPurge(s.config.PurgeBefore)
s.doPurge(s.config.PurgeAfter)
}
}(s)
}
......
......@@ -67,7 +67,7 @@ func TestNewSchedule(t *testing.T) {
}
c.Name = "legit"
c.PurgeBefore = time.Second
c.PurgeAfter = time.Second
s, err = NewSchedule(c)
if s == nil {
t.Error("Schedule with ok name should be created.")
......@@ -80,7 +80,7 @@ func TestNewSchedule(t *testing.T) {
func TestNewScheduleConfig(t *testing.T) {
c := NewScheduleConfig()
if c.PurgeBefore != DefaultPurgeBefore {
if c.PurgeAfter != DefaultPurgeAfter {
t.Error("Incorrect purge after value assigned.")
}
......@@ -150,7 +150,7 @@ func TestSchedule_AutoPurge(t *testing.T) {
Reset()
s, _ := NewSchedule(ScheduleConfig{
Name: "TestSchedule_AutoPurge",
PurgeBefore: time.Second,
PurgeAfter: time.Second,
})
j := newSimpleJob()
j.Cap = 1
......
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