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

fix bug in scheduler, rescheduling jobs immediately #23

Merged
merged 5 commits into from
Apr 10, 2020
Merged

Conversation

JohnRoesler
Copy link
Contributor

package main

import (
	"fmt"
	"time"

	"github.com/go-co-op/gocron"
)

func task() {
	fmt.Printf("Task time: %v\n", time.Now().UTC())
}

func main() {
	s1 := gocron.NewScheduler(time.UTC)
	s1.Every(2).Seconds().StartImmediately().Do(task)
	<-s1.Start() // starts running (blocks current thread)
}

Output:

Task time: 2020-04-10 05:13:40.606502 +0000 UTC
Task time: 2020-04-10 05:13:42.60736 +0000 UTC
Task time: 2020-04-10 05:13:44.608121 +0000 UTC
Task time: 2020-04-10 05:13:46.609026 +0000 UTC
Task time: 2020-04-10 05:13:48.606512 +0000 UTC
Task time: 2020-04-10 05:13:50.608894 +0000 UTC
Task time: 2020-04-10 05:13:52.606553 +0000 UTC
Task time: 2020-04-10 05:13:54.608598 +0000 UTC
Task time: 2020-04-10 05:13:56.606573 +0000 UTC
Task time: 2020-04-10 05:13:58.606552 +0000 UTC
Task time: 2020-04-10 05:14:00.608368 +0000 UTC
Task time: 2020-04-10 05:14:02.606641 +0000 UTC
Task time: 2020-04-10 05:14:04.608286 +0000 UTC
Task time: 2020-04-10 05:14:06.606737 +0000 UTC
Task time: 2020-04-10 05:14:08.608174 +0000 UTC
Task time: 2020-04-10 05:14:10.608141 +0000 UTC
Task time: 2020-04-10 05:14:12.606751 +0000 UTC
Task time: 2020-04-10 05:14:14.607512 +0000 UTC
Task time: 2020-04-10 05:14:16.606776 +0000 UTC
Task time: 2020-04-10 05:14:18.607749 +0000 UTC
Task time: 2020-04-10 05:14:20.606882 +0000 UTC
Task time: 2020-04-10 05:14:22.606922 +0000 UTC
Task time: 2020-04-10 05:14:24.608243 +0000 UTC
Task time: 2020-04-10 05:14:26.608399 +0000 UTC
Task time: 2020-04-10 05:14:28.607878 +0000 UTC
Task time: 2020-04-10 05:14:30.606958 +0000 UTC
Task time: 2020-04-10 05:14:32.607995 +0000 UTC
Task time: 2020-04-10 05:14:34.60762 +0000 UTC
Task time: 2020-04-10 05:14:36.607508 +0000 UTC
Task time: 2020-04-10 05:14:38.60877 +0000 UTC
Task time: 2020-04-10 05:14:40.609291 +0000 UTC
Task time: 2020-04-10 05:14:42.607145 +0000 UTC
Task time: 2020-04-10 05:14:44.608426 +0000 UTC

Closes #20

scheduler.go Outdated Show resolved Hide resolved
Copy link
Member

@Streppel Streppel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just the seconds issue that I've left in there @JohnRoesler, other than that it looks good

scheduler.go Outdated Show resolved Hide resolved
scheduler.go Show resolved Hide resolved
@JohnRoesler
Copy link
Contributor Author

If you all could pull this down and do some testing as well - that would be great. I ran it multiple times last night for ~10 minutes a time. Want to make sure this isn't breaking something else unintentionally. Another reason for us to make some better tests using mocked time 😁

timeHelper.go Outdated Show resolved Hide resolved
@Streppel
Copy link
Member

If you all could pull this down and do some testing as well - that would be great. I ran it multiple times last night for ~10 minutes a time. Want to make sure this isn't breaking something else unintentionally. Another reason for us to make some better tests using mocked time grin

Doing it right now :)! Also I'll make some commits in this branch if you're ok with it

@JohnRoesler
Copy link
Contributor Author

@Streppel go for it!

Copy link
Contributor Author

@JohnRoesler JohnRoesler left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Streppel your changes look good - if you're good with it, then let's merge this!

@Streppel
Copy link
Member

@arjunmahishi any closing thoughts before we merge?

@arjunmahishi
Copy link
Member

Nope.

@Streppel Streppel self-requested a review April 10, 2020 19:43
@Streppel Streppel merged commit 602934f into master Apr 10, 2020
@Streppel Streppel deleted the scheduler-bug branch April 10, 2020 19:44
@Streppel Streppel restored the scheduler-bug branch April 10, 2020 19:44
@github-actions github-actions bot deleted the scheduler-bug branch April 10, 2020 19:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bug in scheduler
3 participants