Skip to content

Commit

Permalink
Exposing job's scheduled unit and interval (#606)
Browse files Browse the repository at this point in the history
* Added String() function to schedulingUnit

* Exposed job's unit and interval

* ScheduledUnit() returns string instead of schedulingUnit

* Gofumpted
  • Loading branch information
chicknsoup committed Nov 10, 2023
1 parent 9993f76 commit 8086065
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
4 changes: 4 additions & 0 deletions gocron.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,10 @@ const (
crontab
)

func (s schedulingUnit) String() string {
return [...]string{"milliseconds", "seconds", "minutes", "hours", "days", "weeks", "months", "duration", "crontab"}[s]
}

func callJobFunc(jobFunc interface{}) {
if jobFunc == nil {
return
Expand Down
10 changes: 10 additions & 0 deletions job.go
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,16 @@ func (j *Job) ScheduledTime() time.Time {
return j.nextRun
}

// ScheduledUnit returns the scheduled unit of the Job.
func (j *Job) ScheduledUnit() string {
return j.unit.String()
}

// Interval returns the scheduled interval of the Job.
func (j *Job) ScheduledInterval() int {
return j.interval
}

// ScheduledAtTime returns the specific time of day the Job will run at.
// If multiple times are set, the earliest time will be returned.
func (j *Job) ScheduledAtTime() string {
Expand Down

0 comments on commit 8086065

Please sign in to comment.