开发者

Rufus-scheduler only running once on production

开发者 https://www.devze.com 2023-04-05 02:04 出处:网络
I\'m using rufus-scheduler to run a process every day from a rails server. For testing purposes, let\'s say every 5 minutes. My code looks like this:

I'm using rufus-scheduler to run a process every day from a rails server. For testing purposes, let's say every 5 minutes. My code looks like this:

in config/initializers/task_scheduler.rb

scheduler = Rufus::Scheduler::PlainScheduler.start_new
scheduler.every "10m", :first_in => '30s' do
 # Do stuff
end

I've also tried the cron format:

scheduler.cron '50 * * * *' do
 # stuff
end

for example, to get the process to run every hour at 50 minutes after the hour.

The infuriating part is that it works on my local machine. The process will run regularly and just work. It's only on my deployed-to-production app that the proces开发者_C百科s will run once, and not repeat.

ps faux reveals that cron is running, passenger is handling the spin-up of the rails process, the site has been pinged again so it knows it should refresh, and production shows the changes in the code. The only thing that's different is that, without a warning or error, the scheduled task doesn't repeat.

Help!


You probably shouldn't run rufus-scheduler in the rails server itself, especially not with a multi-process framework like passenger. Instead, you should run it in a daemon process.

My theory on what's happening:

Passenger starts up a ruby server process and uses it to fork off other servers to handle requests. But since rufus-scheduler runs its jobs in a separate thread from the main thread, the rufus thread is only alive in the original ruby process (ruby's fork only duplicates the thread that does the forking). This might seem like a good thing because it prevents multiple schedulers from running, but... Passenger may kill ruby processes under certain conditions - and if it kills the original, the scheduler thread is gone.


Add the Below lines to your apache2 config /etc/apache2/apach2.conf and restart your apache server

 RailsAppSpawnerIdleTime 0
 PassengerMinInstances 1


Kelvin is right.

Passenger kills 'unnecessary' threads.

http://groups.google.com/group/rufus-ruby/search?group=rufus-ruby&q=passenger

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号