Rufus Scheduler not running

2019-04-15 20:26发布

I want to do something simple with the gem rufus-scheduler: https://github.com/jmettraux/rufus-scheduler

but, i can't get it to work.

I have a regular rails app. I created a .rb file:

# test_rufus_scheduler.rb
require 'rubygems'
require 'rufus/scheduler'

scheduler = Rufus::Scheduler.start_new

scheduler.in '1s' do
  puts "hello world"
end

Then, when I try ruby test_rufus_scheduler.rb, nothing happens. Am i doing it right? gem list shows rufus-scheduler.

Thanks.

3条回答
劫难
2楼-- · 2019-04-15 21:02

If your script exits right away please try to add

scheduler.join

at the end. Please note that it's different when running the script stand alone and via rails. See the README for detailled information.

查看更多
ゆ 、 Hurt°
3楼-- · 2019-04-15 21:05

Found a solution to this here (which also is in sync to Ajet's answer above).

Production servers require a bit of additional setup. On most production web servers, idle Ruby processes are killed. In order for Rufus to work, you'll need to stop this from happening. For Passenger/Nginx you can copy the following code below to your nginx.conf config file for your website after the line that says passenger_enabled on;.

nginx.conf:

passenger_spawn_method direct;
passenger_min_instances 1;
passenger_pool_idle_time 0;
查看更多
爱情/是我丢掉的垃圾
4楼-- · 2019-04-15 21:21

Add the below lines to your apache2 config and restart your apache2 server

RailsAppSpawnerIdleTime 0
PassengerMinInstances 1
查看更多
登录 后发表回答