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

Revert "provide a better panic message when no jobs in scheduler and start blocking called" #503

Merged
merged 1 commit into from
May 30, 2023
Merged
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
1 change: 0 additions & 1 deletion example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -776,7 +776,6 @@ func ExampleScheduler_Stop() {
fmt.Println(s.IsRunning())

s = gocron.NewScheduler(time.UTC)
_, _ = s.Every(1).Second().Do(task)

go func() {
time.Sleep(1 * time.Second)
Expand Down
5 changes: 0 additions & 5 deletions scheduler.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,7 @@ func (s *Scheduler) SetMaxConcurrentJobs(n int, mode limitMode) {

// StartBlocking starts all jobs and blocks the current thread.
// This blocking method can be stopped with Stop() from a separate goroutine.
//
// There must be at least 1 job in the scheduler or a panic will occur.
func (s *Scheduler) StartBlocking() {
if len(s.Jobs()) == 0 {
panic("gocron: scheduler must have at least 1 job before calling StartBlocking")
}
s.StartAsync()
s.startBlockingStopChanMutex.Lock()
s.startBlockingStopChan = make(chan struct{}, 1)
Expand Down
10 changes: 0 additions & 10 deletions scheduler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -996,8 +996,6 @@ func TestScheduler_Stop(t *testing.T) {
})
t.Run("stops a running scheduler calling .Stop()", func(t *testing.T) {
s := NewScheduler(time.UTC)
_, err := s.Every(1).Second().Do(func() {})
require.NoError(t, err)

go func() {
time.Sleep(time.Second)
Expand Down Expand Up @@ -2707,11 +2705,3 @@ func TestScheduler_WithDistributedLocker_With_Name(t *testing.T) {
})
}
}

func TestScheduler_StartBlocking(t *testing.T) {
t.Run("panics if no jobs are added", func(t *testing.T) {
s := NewScheduler(time.UTC)
expected := "gocron: scheduler must have at least 1 job before calling StartBlocking"
assert.PanicsWithValue(t, expected, s.StartBlocking)
})
}