-
-
Notifications
You must be signed in to change notification settings - Fork 313
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
[BUG] - Job is running twice #132
Comments
@sylviamoss I've tested out quite a few jobs locally running every day at a specific time and I haven't been able to reproduce this issue. Have you seen this happen each time the job runs that it runs twice? Are you able to reproduce it? |
@JohnRoesler I figured out that only happens when the application is running in a container. Testing case: func main() {
fmt.Println("start")
scheduler := gocron.NewScheduler(time.UTC)
t := time.Now().Add(1 * time.Minute)
hour := strconv.Itoa(t.Hour())
minute := strconv.Itoa(t.Minute())
at := fmt.Sprintf("%s:%s", hour, minute)
stop := false
if _, err := scheduler.Every(1).Day().At(at).Do(func() { fmt.Println("Starting job"); stop = true }); err != nil {
fmt.Println(err)
return
}
scheduler.StartAsync()
for !stop {
}
time.Sleep(10 * time.Second)
fmt.Println("stop")
} Dockerfile: FROM golang:latest
RUN mkdir /app
ADD . /app/
WORKDIR /app
RUN go build -o main .
CMD ["./main"] This outputs: ➜ test docker build -t test .
...
➜ test docker run test
start
Starting job
Starting job
stop Pretty weird, right? Do you have any idea why this could be happening? It doesn't seem to happen when I change it to use |
Interesting that it only happens in docker - must be something slightly different with how the time is handled. This issue looks to be that the duration until the run isn't quite right:
I upped the Interestingly, on a mac it operates as I'd expect and doesn't enter the afterfunc until the calculated time. |
Seems like in a container the time round is different and Btw, my host OS is mac as well. Have you tested it on some other Linux machine? |
That's weird... Just tested the case you provided and it ran fine here. Will investigate a bit more as well. |
I also just tested it again, and I can't recreate the double run issue. I made a similar setup but used the scratch docker image FROM scratch
COPY ./main /main
CMD ["/main"] package main
import (
"log"
"time"
)
func main() {
now := time.Now()
t := time.Now().Add(10 * time.Second).Round(time.Second)
log.SetFlags(log.Lmicroseconds)
log.Printf("at: %s", t)
durationToNext := t.Sub(now)
time.AfterFunc(durationToNext, func() {
log.Println("hello")
})
time.Sleep(20 * time.Second)
} $ docker run --rm -it test-scratch
> 04:41:15.677798 at: 2021-03-08 04:41:26 +0000 UTC
> 04:41:26.010159 hello |
Please reopen if you continue to see this issue occurring. For now, we'll chalk it up to something odd in the water that day as I haven't be able to recreate it since. |
Hi, faced the same bug in my environment (MacOS + docker). After some debugging, I found that |
Describe the bug
I scheduled a job to run one time a day at a certain time. When is missing 1 sec to the scheduled time, a job instance is started. At the exact scheduled time, another instance will run for the same job. The result is the job running twice with one second of difference.
To Reproduce
Schedule a job like the following:
Version
v0.7.0
Additional context
Output logs of the application I'm running:
This is the log I print as soon as the job starts. Note the difference between the logged times.
The text was updated successfully, but these errors were encountered: