2011-11-22 110 views
2

我試圖從Padrino應用程序異步發送電子郵件 - 我試過使用紅寶石叉命令,但這並不能很好地擴展我想,我也嘗試了delayed_job,但現在有Resque解決方案(主要是因爲它附帶的Web界面非常好)。通過Resque從帕德里諾異步發送電子郵件

我有它的工作,除了我不得不訴諸使用小馬而不是padrino郵件從/ lib發送我的電子郵件。我會很感激任何幫助從圖片中刪除小馬。我遇到的主要問題是我不知道如何從控制器或助手外部調用padrino-mailer。我相信這是可能的,並希望得到任何幫助。如果我們能夠理清這一點,我會認爲這可能對其他Padrino開發人員非常有用 - 發送電子郵件異步可能是Web應用程序非常普遍的核心可伸縮性要求。

看到這裏的信息有關如何安裝和配置Resque: https://github.com/defunkt/resque

然後看看這裏的如何從Padrino通過Resque發送電子郵件異步: https://gist.github.com/1384630


更新 - 我切換使用紅寶石郵件gem從/ lib發送電子郵件 - 請參閱已更新模塊的更新要點,以便通過resque發送異步電子郵件。

我仍然有興趣知道padrino-mailer是否可以強制從/ lib下工作 - 對此的幫助仍然值得讚賞。

回答

1

我喜歡這麼多resque,我用它來一些更復雜的守護進程,我需要優先隊列。

對於在cron風格簡單,但非常靈活的守護進程,你可以看看:https://github.com/daddye/foreverb

的代碼很簡單:

#!/usr/bin/env ruby 
require 'yaml' # not really necessary but some envs need it... 
require 'rubygems' unless defined?(Gem) 
require 'forever' 
boot = File.expand_path('../../config/boot.rb', __FILE__) 

Forever.run :fork => true do 
    before :each do 
    require boot 
    # Here we setup app projects, if you need only once you can do 
    # MyApp.setup_application! 
    # Which load their dependencies 
    Padrino.mounted_apps.each do |app| 
     app.app_obj.setup_application! 
    end 
    end 

    every 1.minutes do 
    MyQueue.each do |q| 
     MyApp.deliver(:notification, q) 
     q.destroy 
    end 
    end 
end 

將這個簡單的文件在你project_root/lib,適用chmod +x file_name來看,它搭配:

./lib/file_name start|stop|restart

最後,如果你需要構建它在你的控制器的enqueue中,你可以建立一個如下所示的簡易隊列表:

MyQueue.create(:from => '[email protected]', :to => '[email protected]', :subject => 'Order changed')