问题
I have a Rails app running on Apache/Passenger. I have a rufus cron job that runs in the background and sends out notifications via email. When I am running the app in development on the WEBrick server, the emails are sent like they are supposed to be sent. When I start up the app in production on Apache/Passenger, then the emails dont get sent. The class doing the work is in config/initializers/task_scheduler.rb
require 'rubygems'
require 'rufus/scheduler'
Rails.logger.info "Starting the scheduler"
## to start scheduler
scheduler = Rufus::Scheduler.start_new
## Every day at 6 AM, send email for projects that haven't been updated in 14 days
Rails.logger.info "Adding the Stale Email job to the scheduler"
scheduler.cron("* * * * *") do
Rails.logger.info "Running every minute"
projects = Project.stale
projects.each do |project|
Rails.logger.info "Inside the loop"
days = (Time.now - project.updated_at).to_i / 1.day
ProjectMailer.stale(Jetway::Application.config.stale_email, project, days).deliver
Rails.logger.info "Sent stale email for project #{project.name}; it's #{days} days stale."
end
end
Right now it is running every minute, so I can debug. Here is my log file output.
Started GET "/assets/availity_spinner.gif" for 99.44.242.76 at 2012-06-23 21:46:28 -0400
Served asset /availity_spinner.gif - 304 Not Modified (0ms)
Starting the scheduler
Adding the Stale Email job to the scheduler
You can see the log statement and how far we get into the code. I have read in blogs that Passenger kills threads, specifically around cron jobs. I am stuck and trying to get a direction to figure out this issue. Please point me in the right direction.
回答1:
Add the below lines to your apache2 config and restart your apache2 server
RailsAppSpawnerIdleTime 0
PassengerMinInstances 1
来源:https://stackoverflow.com/questions/11174563/apache-passenger-rufus-cron-job-not-working