質問

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.

役に立ちましたか?

解決

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.

他のヒント

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

RailsAppSpawnerIdleTime 0
PassengerMinInstances 1

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;
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top