-
Notifications
You must be signed in to change notification settings - Fork 343
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
Scheduled job gets delayed by the running time of the job in a long running (daemon like) program #16
Comments
I have the same problems with my projects. All delay by some time. It's not exactly the time the tasks take to execute. |
I was looking at this project after searching "Golang cron", and liked the idea, but wanted to build it differently without reflection, so I rolled my own. I think the issue is that all the jobs are being run on the same thread, thus if a job of yours takes more than a second, all of your jobs will be delayed by that much. Looking at the code, it'll take some tinkering to make it work properly, as the I'm finding it a little hard to see where that would be useful. If we dropped needing to return the result of the task, we could rewrite the func (j *Job) run() {
// ...
// Instead of throwing an error here when the task is running,
// why not throw an error when the task is added to the scheduler?
// if len(params) != f.Type().NumIn() {
// err = errors.New("The number of param is not adapted.")
// return
// }
// ...
go f.Call(in) // spin off a goroutine so as not to delay subsequent tasks
j.lastRun = time.Now()
j.scheduleNextRun()
} My cursory testing shows this to work, but I've hardly been exhaustive with it. That's my suggestion anyway. |
@jasonlvhit what's the status of this issue? Any plans to resolve? I'm seeing some similar behavior in my project, and honestly if this is not resolved I will need to move away from this lib. |
Does #57 could resolve this issue ? |
Yes #57 solves it, I had the same issue |
Come checkout https://github.com/go-co-op/gocron where we have an active fork of this repo! |
I have written a little tool to backup my database every day at 0:00 and 13:00, thus:
The backup action itself takes around 10~12 seconds. I have set up a logger inside the program, and these are the log output:
As you can see, after each scheduled job being executed, the next job will be delayed by 10~12 seconds which is the execution time of the backup routine.
Is this by design? If yes, is there a way to change the behaviour?
The text was updated successfully, but these errors were encountered: