2012-06-24 48 views
0

我有一個運行在Apache/Passenger上的Rails應用程序。我有一個rufus cron作業,在後臺運行並通過電子郵件發送通知。當我在WEBrick服務器上開發應用程序時,電子郵件就像它們應該發送的那樣發送。當我在Apache/Passenger上開始生產應用程序時,那麼電子郵件就不會被髮送。類做的工作是在配置/初始化/ task_scheduler.rbApache /乘客rufus cron工作不工作

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 

現在它正在運行的每一分鐘,這樣我就可以進行調試。這是我的日誌文件輸出。

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 

您可以看到log語句以及我們進入代碼的距離。我已經在博客中讀到Passenger殺死線程,特別是圍繞cron作業。我被卡住了,試圖找出解決這個問題的方向。請指向正確的方向。

回答

2

以下行添加到您的Apache2配置和重新啓動的Apache2服務器

RailsAppSpawnerIdleTime 0 
PassengerMinInstances 1