-
Notifications
You must be signed in to change notification settings - Fork 236
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
Use rufus job's schedule time to determine if a specific job instance has ran before #181
Comments
Hi @snmgian - can this cause a job to be scheduled twice in a row? I believe I encountered this recently. |
Hi @benjaminwood, what schedule types (https://github.com/moove-it/sidekiq-scheduler#schedule-types) are you using within your configuration? |
The job that was run twice was using the cron schedule-type. Specifically:
|
Yes, it can happen under some circumstances. Basically we are saving the timestamps ( This approach works most of the time unless some runtime condition (cpu load, network latency, redis latency) causes the job to be triggered in the next second that the one was supposed to. One of the possible approaches is to infer the timestamp at which the job should've exactly triggered ... |
@snmgian thanks for the response. Can you explain this a bit more?
I realize that sidekiq jobs should be idempotent, but the sad truth is that people regularly ignore this rule. So, this bug has the potential to do some damage in certain cases. Until this bug is fixed, I think we should add a notice/warning in the readme that jobs may be run multiple times, one after another. So, it is important (as always) to ensure that your scheduled jobs are idempotent. |
Suppose we have
|
Very good, hopefully the added documentation will provide a clue to new users that are experiencing duplicate execution. Are you considering this a bug? Are there plans to address the issue so that it does not happen? I understand that it is a fundamental problem and the reliance on rufus-scheduler is at the center of it. Just curious how you view it at this point in time. |
The gem wasn't designed with the idea of running in multiple nodes in mind. Today, I think this is a must have. But before start to tackling this, the code and the overall design must be published. Some work is being done regarding that refactoring, but it's not finished yet. |
Hi snmgian, has this issue been fixed? My scheduled jobs are used to send out email reminders for work with in my production app. Right now this is causing people to get spammed pretty much. I was wondering if there was a fix for this or if you think I should just use rufus to schedule jobs in sidekiq? |
Hi @ronval, what do you have in your sidekiq scheduler configuration? Does your users receive email reminders twice? |
Yes They were getting it more than that actually. They were getting them 4 times. I have a pretty basic setup. Heroku 2 web dynos 2 workers dynos. The sidekiq config file is. (Its properly formated too). Thanks again for you help.
|
Hi @ronval Don't use
Why do you specified So if you restart the worker (for any reason) every hour, the job will be scheduler 120 seconds after each startup. I'm not sure if that's what you want ... but I think it's not. Another reason why I think
You can also specify the time zone Note: the snippet you provided here has bad formatting, but I think I got the idea. Anyway, you should wrap the code using |
Hi @snmgian This is what the sidekiq server said: #INITALIZER Sidekiq.configure_server do |config| config.on(:startup) do
end this is the schedule.yml reminder_queue: this is the procfile web: bundle exec puma -C config/puma.rb |
I'm also experiencing the same problem. When you have a heavy thread contention, rufus-scheduler schedule checks might be executed less frequently than 3 times/second – e.g. every other second. Since Here is an example that shows how rufus-scheduler might deviate from the cron schedule under heavy thread contention:
|
Thanks for the reply. I ended up making a statemachine. Just keeping track when it should run on the DB. If the date was the right date then it runs. It works fine now. Thanks :) |
Hello there, I've been reading through multiple issues related to this matter and it boiled down to one single question for me: is it unsafe to use sidekiq-scheduler in auto-scalable sidekiq instance group just now? Or would you rather suggest using a lightweight process (rufus-scheduler/clockwork) on a separate instance which sole responsibility would be looking after the schedule and enqueue jobs for now? PS: Thanks for the gem btw, idea of doing scheduling on redis side feels right. |
My setup is running on heroku So for me what was happening was that heroku
would restart the server at least once a day which is just normal behavior.
What that was doing was it made it reset the scheduler. I made it have its
own worker instance in heroku but same thing was happening. So what I did
was just made it run everyday but I added a DB table that kept track if it
should run the processes by saving the date. when it ran I update the
date/time depending on how often I wanted it to run comparing it to the
current date time . Its working great. So now I can have all the processes
I need to run with out worring about the resets or too many things running
cause I have too many instances. So we are good with it at my startup :) I
hope that helps you out.
…On Thu, Dec 27, 2018, 9:00 PM Yaroslav F. ***@***.*** wrote:
Hello there,
I've been reading through multiple issues related to this matter and it
boiled down to one single question for me: is it unsafe to use
sidekiq-scheduler in auto-scalable sidekiq instance group just now? Or
would you rather suggest using a lightweight process
(rufus-scheduler/clockwork) on a separate instance which sole
responsibility would be looking after the schedule and enqueue jobs for now?
PS: Thanks for the gem btw, idea of doing scheduling on redis side feels
right.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#181 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AIYMNNsUuM66KzDtZgHfQG0KOcd3oESyks5u9JowgaJpZM4NJzKV>
.
|
Job's schedule time is the timestamp at which a rufus job instance was scheduled to be triggered.
rufus-scheduler gets
EoTime.now
and then triggers each job passing that time to#trigger
method.This could cause problems if
Rufus::Scheduler#trigger_jobs
is invoked a second after a particular jobs has been triggered.The text was updated successfully, but these errors were encountered: