Commit 03caa6be authored by Kyle Clarke's avatar Kyle Clarke 💬

Added all expected comments as per go lint

parent 97663206
package kevin
// KevinError is the package level error struct.
type KevinError struct {
// Error is the package level error struct.
type Error struct {
s string
}
var (
// Kevin Schedule and Job Errors
ErrScheduleNotFound = NewKevinError("Schedule not found.")
// ErrScheduleNotFound occurs when unable to find a schedule by name.
ErrScheduleNotFound = NewKevinError("Schedule not found.")
// ErrScheduleDuplicateName occurs when creating a new schedule of the same name.
ErrScheduleDuplicateName = NewKevinError("New schedule creation attempt with duplicate name.")
ErrScheduleEmptyName = NewKevinError("New schedule creation attempt with empty name.")
ErrScheduleJobNotFound = NewKevinError("Scheduled job not found.")
ErrDurationZero = NewKevinError("Task duration of zero is not allowed.")
ErrJobDuplicateId = NewKevinError("Add job attempted on schedule with duplicate job ID.")
// ErrScheduleEmptyName occurs when creating a new schedule with an empty string.
ErrScheduleEmptyName = NewKevinError("New schedule creation attempt with empty name.")
// ErrScheduleJobNotFound occurs when unable to find a job runner by id.
ErrScheduleJobNotFound = NewKevinError("Scheduled job not found.")
// ErrDurationZero occurs when adding a new job, but the every duration is zero.
ErrDurationZero = NewKevinError("Task duration of zero is not allowed.")
// ErrJobDuplicateID occurs when adding a new job with an id that already exists on the schedule.
ErrJobDuplicateID = NewKevinError("Add job attempted on schedule with duplicate job ID.")
// ErrJobFunctionParamMismatch occurs when the fn params passed do not match the fn params required.
ErrJobFunctionParamMismatch = NewKevinError("Mismatch in params passed to assigned Fn.")
ErrJobNonFunctionType = NewKevinError("Fn assigned not of func type.")
ErrJobMaximumTickBreach = NewKevinError("The job Every ticker has reached the maximum uint64 number of ticks.")
ErrJobOrphaned = NewKevinError("The executing job is no longer assigned to it's schedule. Orphaned rogue.")
// ErrJobNonFunctionType occurs when the string value passed does not match a valid function.
ErrJobNonFunctionType = NewKevinError("Fn assigned not of func type.")
// ErrJobMaximumTickBreach occurs when a jobs running count breaches the uint64 limit.
ErrJobMaximumTickBreach = NewKevinError("The job Every ticker has reached the maximum uint64 number of ticks.")
// ErrJobOrphaned occurs when a running job cannot find the schedule that should contain it.
ErrJobOrphaned = NewKevinError("The executing job is no longer assigned to it's schedule. Orphaned rogue.")
)
// Error() will return the error string value.
func (e KevinError) Error() string {
func (e Error) Error() string {
return e.s
}
// IsKevinError will return true on KevinError instance.
func IsKevinError(err error) bool {
_, ok := err.(*KevinError)
_, ok := err.(*Error)
return ok
}
// NewKevinError will return a new KevinError instance.
func NewKevinError(errorMessage string) error {
return &KevinError{errorMessage}
return &Error{errorMessage}
}
......@@ -6,18 +6,24 @@ import (
)
const (
DefaultName = "default"
// 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
DefaultPurgePoll = time.Hour
)
var pool *SchedulePool = &SchedulePool{
schedules: make(Schedules),
defaultPurgeBefore: DefaultPurgeBefore,
defaultPurgePoll: DefaultPurgePoll,
}
// DefaultPurgePoll is the duration used to auto purge schedules.
DefaultPurgePoll = time.Hour
)
var pool *SchedulePool
func init() {
pool = &SchedulePool{
schedules: make(Schedules),
defaultPurgeBefore: DefaultPurgeBefore,
defaultPurgePoll: DefaultPurgePoll,
}
// Setup the default schedule on load
DefaultSchedule()
}
......@@ -102,7 +108,7 @@ func IsEmpty() bool {
return true
}
// PurgePolling sets a duration to purge schedules within this pool.
// PurgePollingInterval sets a duration to purge schedules within this pool.
func PurgePollingInterval(d time.Duration) {
pool.defaultPurgePoll = d
for _, s := range All() {
......
......@@ -7,15 +7,26 @@ import (
)
const (
StatusRunning = "Running"
StatusStopped = "Stopped"
StatusError = "Error"
StatusExpired = "Expired"
// StatusRunning is a simple string representation of a running status
StatusRunning = "Running"
// StatusStopped is a simple string representation of a stopped status
StatusStopped = "Stopped"
// StatusError is a simple string representation of an error status
StatusError = "Error"
// StatusExpired is a simple string representation of an expired status
StatusExpired = "Expired"
// StatusCapBreached is a simple string representation of a cap breached status
StatusCapBreached = "Cap Breached"
// StatusCannotBegin is a simple string representation of a cannot begin status
StatusCannotBegin = "Cannot Begin"
)
// JobRunners are a map of all job runners key'd on JobID.
// Runners are a map of all job runners key'd on JobID.
type Runners map[JobID]*JobRunner
// JobRunner struct to contain meta data and the runner task.
......@@ -185,7 +196,6 @@ func (i JobRunnerInfo) IsPending() bool {
return (!i.IsCompleted() && i.StartedAt.IsZero())
}
// IsRunning will return true if not complete and started.
func (i JobRunnerInfo) IsRunning() bool {
return (!i.IsCompleted() && !i.StartedAt.IsZero())
......
......@@ -22,7 +22,7 @@ type ScheduleConfig struct {
PurgePoll time.Duration
}
// SchedulesInfo represents information about all Schedulers assigned to the schedule pool.
// ScheduleInfo represents information about all Schedulers assigned to the schedule pool.
type ScheduleInfo struct {
Name string
Count int64
......@@ -58,7 +58,7 @@ type Job struct {
schedule *Schedule
}
// A convenience method to added params to the Job instance.
// AddFnParams is a convenience method to added params to the Job instance.
func (j *Job) AddFnParams(params ...interface{}) {
j.FnParams = append(j.FnParams, params...)
}
......@@ -82,10 +82,10 @@ func NewSchedule(sc ScheduleConfig) (*Schedule, error) {
pool.Unlock()
if ok {
return nil, ErrScheduleDuplicateName
} else {
pool.schedules[sc.Name] = schedule
}
pool.schedules[sc.Name] = schedule
// Setup the AutoPurge for this Schedule.
schedule.AutoPurge(sc.PurgePoll)
......@@ -113,7 +113,7 @@ func (s *Schedule) Add(j *Job) (JobID, error) {
_, ok := s.runners[j.ID]
s.Unlock()
if ok {
return j.ID, ErrJobDuplicateId
return j.ID, ErrJobDuplicateID
}
// Assign this schedule
......@@ -248,7 +248,7 @@ func (s *Schedule) Reset() error {
return nil
}
// Reset will attempt to stop the execution on the next job runner from this schedule.
// Stop will attempt to stop the execution on the next job runner from this schedule.
func (s *Schedule) Stop(ID JobID) error {
r, err := s.Find(ID)
if err != nil {
......
......@@ -141,7 +141,7 @@ func TestSchedule_Add(t *testing.T) {
t.Error("Expecting a error on add with duplicate ID.")
}
if err != ErrJobDuplicateId {
if err != ErrJobDuplicateID {
t.Error("Expecting a duplicate ID error on add.")
}
}
......@@ -402,7 +402,7 @@ func TestSchedule_Run(t *testing.T) {
t.Error("Expecting a error on run with duplicate ID.")
}
if err != ErrJobDuplicateId {
if err != ErrJobDuplicateID {
t.Error("Expecting a duplicate ID error on run.")
}
}
......
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