Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(cron): adding the IsRunning function #495

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions cron.go
Original file line number Diff line number Diff line change
Expand Up @@ -353,3 +353,8 @@ func (c *Cron) removeEntry(id EntryID) {
}
c.entries = entries
}

// IsRunning returns the status of the cron scheduler
func (c *Cron) IsRunning() bool {
return c.running
}
19 changes: 19 additions & 0 deletions cron_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -687,6 +687,25 @@ func wait(wg *sync.WaitGroup) chan bool {
return ch
}

func TestIsRunning(t *testing.T) {
wg := &sync.WaitGroup{}
wg.Add(1)
cron := New()
cron.AddFunc("* * * * * ?", func() { wg.Done() })

cron.Start()
time.Sleep(OneSecond)
if !cron.IsRunning() {
t.Error("cron is reporting as not running when it should be running")
}

cron.Stop()
time.Sleep(OneSecond)
if cron.IsRunning() {
t.Error("cron is reporting as running when it should be not running")
}
}

func stop(cron *Cron) chan bool {
ch := make(chan bool)
go func() {
Expand Down