2010-06-09 5 views
4

암호를 재설정하기 위해 사용자에게 전자 메일을 보내려 할 때 실행 시간 초과 오류가 계속 발생합니다. 다른 메일러 기능이 작동하므로 구성 설정이 정확하다는 것을 알고 있습니다. 헤더 읽기 : 여기 ActionMailer 실행 제한 시간

가 password_resets_controller이다 "암호 resetsController 번호에서 시간 초과 : 오류 생성"여기
def create 
@user = User.find_by_email(params[:email]) 
if @user 
    User.deliver_password_reset_instructions(@user.id) 
    flash[:notice] = "Instructions to reset your password have been emailed to you. " + 
    "Please check your email." 
    redirect_to '/' 
else 
    flash[:notice] = "No user was found with that email address" 
    render :action => :new 
end 
end 

여기, 마지막으로
def self.deliver_password_reset_instructions(user_id) 
user = User.find(user_id) 
user.reset_perishable_token! 
Emailer.deliver_password_reset_instructions(user) 
end 

User.rb

의 내부의 방법입니다 emailer.rb의 실제 메소드입니다.

default_url_options[:host] = "http://0.0.0.0:3000" #development 
def password_reset_instructions(user) 
    @subject       = "Application Password Reset" 
    @from        = '[email protected]' 
    @recipients       = user.email 
    @sent_on       = Time.now 
    @body["edit_password_reset_url"] = edit_password_reset_url(user.perishable_token) 
    @headers["X-SMTPAPI"] = "{\"category\" : \"Password Recovery\"}"#send grid category header 
    end 

왜 "비밀번호"가 n 시간 초과 :: 오류를 일으키는 오류 메시지

답변

1

주 컨트롤러 요청 스레드에서 전자 메일 (또는 다른 장기 실행 프로세스)을 보내는 것은 좋은 생각이 아닙니다. 이메일 전송은 아웃 바운드 이메일 전송 서버가 다운되는 등 사용자의 통제하에 있지 않은 여러 가지 이유로 시간이 초과 될 수 있으며 애플리케이션 서버와 사용자가 그로 인해 어려움을 겪는 것을 원하지 않습니다.

지연된 작업 (DJ)과 같은 큐 메커니즘을 사용하여 이러한 전자 메일 작업을 큐에 넣고 컨트롤러 스레드 외부에서 처리되도록하는 것이 더 좋습니다.

이 레일 응용 프로그램에이의 https://github.com/collectiveidea/delayed_job

통합 (또는 다른 큐잉 시스템)를 참조하는 것은 매우 간단하다. 그리고 레일 4는 큐잉 서비스 (내가 아직 사용하지 않고있는)를 내장하고 있다고한다. http://blog.remarkablelabs.com/2012/12/asynchronous-action-mailer-rails-4-countdown-to-2013. 앱에서 DJ를 사용하는 경우

예를 들어, 새로운 코드는 작업이 데이터베이스에 저장되고, 시간 초과와 같은 오류가 발생하면 재 - 시도

def self.deliver_password_reset_instructions(user_id) 
user = User.find(user_id) 
user.reset_perishable_token! 
# this is the only line that changes 
Emailer.delay.deliver_password_reset_instructions(user) 
end 

아래처럼 보일 것입니다.

github 페이지에서 DJ에 대해 자세히 읽을 수 있습니다.