Search code examples
ruby-on-railsdelayed-jobauthlogicdreamhostruby-daemons

Authlogic & delayed_job & delayed_jobl_mailer & daemons?


[edit] I can delay all mail using delayed_job plugin on a shared server with a daemon… except the mail using authlogic. I don't know where I have to search, and why it is working in other way.

daemons (off) delayed_job & delayed_mail_mailer (on) authlogic (reset_password) : send daemons (on) delayed_job & delayed_mail_mailer (on) other_model (send_mail) : send daemons (on) delayed_job & delayed_mail_mailer (on) authlogic (reset_password) : nothing !

Where to search the problem ??

app/initializer/delayed_mailer.rb :

class ActionMailer::Base
  include Delayed::Mailer
end

config/initializers/delayed_job_config.rb :

Delayed::Job.destroy_failed_jobs = false
silence_warnings do
  Delayed::Job.const_set("MAX_ATTEMPTS", 3)
  Delayed::Job.const_set("MAX_RUN_TIME", 5.minutes)
end

script/dalayed_job :

#!/usr/bin/env ruby 
require 'rubygems' 
require 'daemons' 
dir = File.expand_path(File.join(File.dirname(__FILE__), '..')) 
daemon_options = { 
  :multiple   => false, 
  :dir_mode   => :normal, 
  :dir        => File.join(dir, 'tmp', 'pids'), 
  :backtrace  => true, 
  :log_output => true 
} 

Daemons.run_proc('delayed_job', daemon_options) do 
  Dir.chdir dir 
  RAILS_ENV = ENV['RAILS_ENV'] || 'development' 
  require File.join('config', 'environment') 
  Delayed::Worker.new.start 
end

model/controllers/passwoed_reset_controller.rb

  def create
    @user = User.find_by_email(params[:email])
    if @user
      Notifier::deliver_password_reset_instructions(@user)
      flash[:notice] =  t('ResetInstructionSend') + t('CheckMail')
      redirect_to root_url
    else
      flash[:notice] = t('NoUserMail')
      render :action => :new
    end
  end

controllers/other_controller.rb

 def update    
    @patent = Patent.find(params[:id])
    # update all
    @patent.update_attributes(params[:patent])
      @user = @patent.user
      @skill = @patent.skill
      @current_user = current_user
      Notifier::deliver_specialist_confirmation(@user, @skill, @current_user)
   end

models/notifier.rb

def password_reset_instructions(user)
    recipients user.email
    from       "Skill Forest"
    subject       "Password Reset Instructions"
    body          :edit_password_reset_url => edit_password_reset_url(user.perishable_token),:user => user

end

def specialist_confirmation (user, skill, current_user)
  recipients  user.email
  from       "Skill Forest"
  subject    "Bravo"
  body        :user => user, :skill => skill, :current_user => current_user
end

More infos : Rails 2.3.5 & tobi delayed_job & daemons 1.0.10 I'm on dreamhost shared web hosting, but look the same on development mode on my computer.

[Edit 2] I will control to be sure, but seems it was only the max run time too short…

[Edit 3] an other way I'm trying : control if pid exist


Solution

  • Just to turn the page… passing in Rails 3 and updating gem… everything fine. And much simpler.

    Mystery of binary coding !