I am using Rufus Scheduler to trigger the background jobs that need to run every 1 hour.
scheduler = Rufus::Scheduler.singleton
scheduler.every '1h' do
JobName.perform_now
end
I have my Infra setup in AWS and for production, I have 2 Instances running the APP inside an ECS.
What happens is that the Scheduler schedules the jobs twice.
Instance A schedules the job at 00:00:05:01 and Instance B schedules at 00:00:05:05
The jobs are not failing. I am using ActiveJob. I was looking into other solutions like delayed Job but that has the same problem when there are multiple instances.
Can you guys provide an alternate approach to fix this issue? Or a workaround for the same?
https://github.com/jmettraux/rufus-scheduler#lockfile--mylockfiletxt
"This is useful in environments where the Ruby process holding the scheduler gets started multiple times."
Try this: