0

I had setup scheduler in my rails3 projects's /configs/initializers/schedule.rb and it working fine, But it works 2 times and I think it is due to unicorn workers execute schedule at the same time, so it create in my database two records each time. I checked my logic and its ok and enter single record in my local machine.

I checked following but not getting idea how to stop multiple unicorn workers to execute scheduler?

https://github.com/jmettraux/rufus-scheduler/#advanced-lock-schemes

Any one got this issue? Please help if any idea.

Thanks,

P Shah

jmettraux
  • 3,511
  • 3
  • 31
  • 30
Priyank
  • 69
  • 10

2 Answers2

1

try this

require 'rufus-scheduler'

scheduler = Rufus::Scheduler.new(:lockfile => ".rufus-scheduler.lock")

unless scheduler.down?

  scheduler.every("60") do
    # ...
  end
end
Bhargav Rao
  • 50,140
  • 28
  • 121
  • 140
msmukesh4
  • 589
  • 4
  • 7
0

Please try the solution described in https://github.com/jmettraux/rufus-scheduler/#lockfile--mylockfiletxt

jmettraux
  • 3,511
  • 3
  • 31
  • 30