0

我正在开发一个 Rails 3.2.5 应用程序,使用 Sorcery 进行身份验证,使用 delay_job 进行后台处理 [ sorcery (0.7.12)、delayed_job (3.0.3)、delayed_job_active_record (0.3.2) ]。

我的巫术配置如下:

Rails.application.config.sorcery.submodules = [:remember_me, :reset_password, :user_activation, :brute_force_protection, :activity_logging, :external]

Rails.application.config.sorcery.configure do |config|
  --[clip]

  config.user_config do |user|
    user.user_activation_mailer = UserMailer
    user.activation_success_email_method_name = nil
  end

  config.user_class = "Account"
  module Sorcery
    module Model
      module InstanceMethods
        def generic_send_email(method, mailer)
          config = sorcery_config
          mail = config.send(mailer).delay.send(config.send(method), self)
        end
      end
    end
  end
end

宝石文件

source 'https://rubygems.org'

gem 'rails', '3.2.5'

# gem 'thin' # delayed_job has problems with this

gem 'pg'
gem 'mongrel', '1.2.0.pre2'
gem 'bcrypt-ruby', '~> 3.0.0'
gem 'sorcery'
gem 'simple_form'
gem 'high_voltage' # static pages
gem 'squeel'
gem 'kaminari'
gem 'bourbon'
gem 'rabl'
gem 'yajl-ruby'
gem 'geocoder'
gem "carrierwave"
gem "cloudinary"
gem 'haml'
gem 'rails-settings-cached'
gem 'configatron'
gem 'store_configurable'
gem 'has_serialized'
gem 'rolify'
gem 'cancan'
gem 'delayed_job_active_record'
gem 'simple_postmark'

# Gems used only for assets and not required
# in production environments by default.
group :assets do
    gem 'bootstrap-sass'
  gem 'sass-rails', '~> 3.2.3'
  gem 'uglifier', '>= 1.0.3'
  gem 'therubyracer'
  gem 'execjs'
end

gem 'jquery-rails'

group :development, :test do
   gem 'rspec'
   gem 'rspec-rails' , ">= 2.5.0"
   gem 'rails3-generators'
   gem 'hpricot'  # needed by devise views generator
   gem 'awesome_print'
end

创建帐户时,将作业添加到延迟作业表但出现错误:

"{Job failed to load: uninitialized constant BCrypt. Handler: "--- !ruby/object:Delayed::PerformableMailer \nargs: \n- :activation_needed_email_method_name\n- !ruby/ActiveRecord:Account \n  attributes: \n    id: 100\n    username: student.ten@retinaindia.org\n    email: student.ten@retinaindia.org\n    crypted_password: !str:BCrypt::Password \n      str: $2a$10$ndL2tnPLheemvBsNqPXMwew6Pakf/Kf8xxt1Q54xkRWS3JfMaTAC6\n      :@checksum: w6Pakf/Kf8xxt1Q54xkRWS3JfMaTAC6\n      :@cost: 10\n      :@salt: $2a$10$ndL2tnPLheemvBsNqPXMwe\n      :@version: !str:BCrypt::Password 2a\n    salt: Aatzxp2m4fp2CYy9ZoCr\n    user_id: 74\n    user_type: Student\n    created_at: &id001 2012-07-09 08:34:23.981292 Z\n    updated_at: *id001\n    remember_me_token: \n    remember_me_token_expires_at: \n    reset_password_token: \n    reset_password_token_expires_at: \n    reset_password_email_sent_at: \n    failed_logins_count: 0\n    lock_expires_at: \n    unlock_token: \n    last_login_at: \n    last_logout_at: \n    last_activity_at: \n    activation_state: pending\n    activation_token: 7XAssTaEqsorDWpbpUY9\n    activation_token_expires_at: \n    created_by: Admin\nmethod_name: :send\nobject: !ruby/class UserMailer\n"
/home/syed/.rvm/gems/ruby-1.9.2-p0/gems/delayed_job-3.0.3/lib/delayed/backend/base.rb:86:in `rescue in payload_object'
/home/syed/.rvm/gems/ruby-1.9.2-p0/gems/delayed_job-3.0.3/lib/delayed/backend/base.rb:84:in `payload_object'
/home/syed/.rvm/gems/ruby-1.9.2-p0/gems/delayed_job-3.0.3/lib/delayed/backend/base.rb:94:in `block in invoke_job'
/home/syed/.rvm/gems/ruby-1.9.2-p0/gems/delayed_job-3.0.3/lib/delayed/lifecycle.rb:60:in `call'
/home/syed/.rvm/gems/ruby-1.9.2-p0/gems/delayed_job-3.0.3/lib/delayed/lifecycle.rb:60:in `block in initialize'
/home/syed/.rvm/gems/ruby-1.9.2-p0/gems/delayed_job-3.0.3/lib/delayed/lifecycle.rb:65:in `call'
/home/syed/.rvm/gems/ruby-1.9.2-p0/gems/delayed_job-3.0.3/lib/delayed/lifecycle.rb:65:in `execute'
/home/syed/.rvm/gems/ruby-1.9.2-p0/gems/delayed_job-3.0.3/lib/delayed/lifecycle.rb:38:in `run_callbacks'
/home/syed/.rvm/gems/ruby-1.9.2-p0/gems/delayed_job-3.0.3/lib/delayed/backend/base.rb:91:in `invoke_job'
/home/syed/.rvm/gems/ruby-1.9.2-p0/gems/delayed_job-3.0.3/lib/delayed/worker.rb:182:in `block (2 levels) in run'
/home/syed/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/timeout.rb:57:in `timeout'
/home/syed/.rvm/gems/ruby-1.9.2-p0/gems/delayed_job-3.0.3/lib/delayed/worker.rb:182:in `block in run'
/home/syed/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/benchmark.rb:309:in `realtime'
/home/syed/.rvm/gems/ruby-1.9.2-p0/gems/delayed_job-3.0.3/lib/delayed/worker.rb:181:in `run'
/home/syed/.rvm/gems/ruby-1.9.2-p0/gems/delayed_job-3.0.3/lib/delayed/worker.rb:238:in `block in reserve_and_run_one_job'
/home/syed/.rvm/gems/ruby-1.9.2-p0/gems/delayed_job-3.0.3/lib/delayed/lifecycle.rb:60:in `call'
/home/syed/.rvm/gems/ruby-1.9.2-p0/gems/delayed_job-3.0.3/lib/delayed/lifecycle.rb:60:in `block in initialize'
/home/syed/.rvm/gems/ruby-1.9.2-p0/gems/delayed_job-3.0.3/lib/delayed/lifecycle.rb:65:in `call'
/home/syed/.rvm/gems/ruby-1.9.2-p0/gems/delayed_job-3.0.3/lib/delayed/lifecycle.rb:65:in `execute'
/home/syed/.rvm/gems/ruby-1.9.2-p0/gems/delayed_job-3.0.3/lib/delayed/lifecycle.rb:38:in `run_callbacks'
/home/syed/.rvm/gems/ruby-1.9.2-p0/gems/delayed_job-3.0.3/lib/delayed/worker.rb:238:in `reserve_and_run_one_job'
/home/syed/.rvm/gems/ruby-1.9.2-p0/gems/delayed_job-3.0.3/lib/delayed/worker.rb:166:in `block in work_off'
/home/syed/.rvm/gems/ruby-1.9.2-p0/gems/delayed_job-3.0.3/lib/delayed/worker.rb:165:in `times'
/home/syed/.rvm/gems/ruby-1.9.2-p0/gems/delayed_job-3.0.3/lib/delayed/worker.rb:165:in `work_off'
/home/syed/.rvm/gems/ruby-1.9.2-p0/gems/delayed_job-3.0.3/lib/delayed/worker.rb:133:in `block (4 levels) in start'
/home/syed/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/benchmark.rb:309:in `realtime'
/home/syed/.rvm/gems/ruby-1.9.2-p0/gems/delayed_job-3.0.3/lib/delayed/worker.rb:132:in `block (3 levels) in start'
/home/syed/.rvm/gems/ruby-1.9.2-p0/gems/delayed_job-3.0.3/lib/delayed/lifecycle.rb:60:in `call'
/home/syed/.rvm/gems/ruby-1.9.2-p0/gems/delayed_job-3.0.3/lib/delayed/lifecycle.rb:60:in `block in initialize'
/home/syed/.rvm/gems/ruby-1.9.2-p0/gems/delayed_job-3.0.3/lib/delayed/lifecycle.rb:65:in `call'
/home/syed/.rvm/gems/ruby-1.9.2-p0/gems/delayed_job-3.0.3/lib/delayed/lifecycle.rb:65:in `execute'
/home/syed/.rvm/gems/ruby-1.9.2-p0/gems/delayed_job-3.0.3/lib/delayed/lifecycle.rb:38:in `run_callbacks'
/home/syed/.rvm/gems/ruby-1.9.2-p0/gems/delayed_job-3.0.3/lib/delayed/worker.rb:129:in `block (2 levels) in start'
/home/syed/.rvm/gems/ruby-1.9.2-p0/gems/delayed_job-3.0.3/lib/delayed/worker.rb:128:in `loop'
/home/syed/.rvm/gems/ruby-1.9.2-p0/gems/delayed_job-3.0.3/lib/delayed/worker.rb:128:in `block in start'
/home/syed/.rvm/gems/ruby-1.9.2-p0/gems/delayed_job-3.0.3/lib/delayed/plugins/clear_locks.rb:7:in `call'
/home/syed/.rvm/gems/ruby-1.9.2-p0/gems/delayed_job-3.0.3/lib/delayed/plugins/clear_locks.rb:7:in `block (2 levels) in <class:ClearLocks>'
/home/syed/.rvm/gems/ruby-1.9.2-p0/gems/delayed_job-3.0.3/lib/delayed/lifecycle.rb:78:in `call'
/home/syed/.rvm/gems/ruby-1.9.2-p0/gems/delayed_job-3.0.3/lib/delayed/lifecycle.rb:78:in `block (2 levels) in add'
/home/syed/.rvm/gems/ruby-1.9.2-p0/gems/delayed_job-3.0.3/lib/delayed/lifecycle.rb:60:in `call'
/home/syed/.rvm/gems/ruby-1.9.2-p0/gems/delayed_job-3.0.3/lib/delayed/lifecycle.rb:60:in `block in initialize'
/home/syed/.rvm/gems/ruby-1.9.2-p0/gems/delayed_job-3.0.3/lib/delayed/lifecycle.rb:78:in `call'
/home/syed/.rvm/gems/ruby-1.9.2-p0/gems/delayed_job-3.0.3/lib/delayed/lifecycle.rb:78:in `block in add'
/home/syed/.rvm/gems/ruby-1.9.2-p0/gems/delayed_job-3.0.3/lib/delayed/lifecycle.rb:65:in `call'
/home/syed/.rvm/gems/ruby-1.9.2-p0/gems/delayed_job-3.0.3/lib/delayed/lifecycle.rb:65:in `execute'
/home/syed/.rvm/gems/ruby-1.9.2-p0/gems/delayed_job-3.0.3/lib/delayed/lifecycle.rb:38:in `run_callbacks'
/home/syed/.rvm/gems/ruby-1.9.2-p0/gems/delayed_job-3.0.3/lib/delayed/worker.rb:127:in `start'
/home/syed/.rvm/gems/ruby-1.9.2-p0/gems/delayed_job-3.0.3/lib/delayed/command.rb:101:in `run'
/home/syed/.rvm/gems/ruby-1.9.2-p0/gems/delayed_job-3.0.3/lib/delayed/command.rb:89:in `block in run_process'
/home/syed/.rvm/gems/ruby-1.9.2-p0/gems/daemons-1.0.10/lib/daemons/application.rb:215:in `call'
/home/syed/.rvm/gems/ruby-1.9.2-p0/gems/daemons-1.0.10/lib/daemons/application.rb:215:in `block in start_proc'
/home/syed/.rvm/gems/ruby-1.9.2-p0/gems/daemons-1.0.10/lib/daemons/daemonize.rb:192:in `call'
/home/syed/.rvm/gems/ruby-1.9.2-p0/gems/daemons-1.0.10/lib/daemons/daemonize.rb:192:in `call_as_daemon'
/home/syed/.rvm/gems/ruby-1.9.2-p0/gems/daemons-1.0.10/lib/daemons/application.rb:219:in `start_proc'
/home/syed/.rvm/gems/ruby-1.9.2-p0/gems/daemons-1.0.10/lib/daemons/application.rb:255:in `start'
/home/syed/.rvm/gems/ruby-1.9.2-p0/gems/daemons-1.0.10/lib/daemons/application_group.rb:123:in `block (2 levels) in start_all'
/home/syed/.rvm/gems/ruby-1.9.2-p0/gems/daemons-1.0.10/lib/daemons/application_group.rb:122:in `fork'
/home/syed/.rvm/gems/ruby-1.9.2-p0/gems/daemons-1.0.10/lib/daemons/application_group.rb:122:in `block in start_all'
/home/syed/.rvm/gems/ruby-1.9.2-p0/gems/daemons-1.0.10/lib/daemons/application_group.rb:121:in `each'
/home/syed/.rvm/gems/ruby-1.9.2-p0/gems/daemons-1.0.10/lib/daemons/application_group.rb:121:in `start_all'
/home/syed/.rvm/gems/ruby-1.9.2-p0/gems/daemons-1.0.10/lib/daemons/controller.rb:79:in `run'
/home/syed/.rvm/gems/ruby-1.9.2-p0/gems/daemons-1.0.10/lib/daemons.rb:188:in `block in run_proc'
/home/syed/.rvm/gems/ruby-1.9.2-p0/gems/daemons-1.0.10/lib/daemons/cmdline.rb:105:in `call'
/home/syed/.rvm/gems/ruby-1.9.2-p0/gems/daemons-1.0.10/lib/daemons/cmdline.rb:105:in `catch_exceptions'
/home/syed/.rvm/gems/ruby-1.9.2-p0/gems/daemons-1.0.10/lib/daemons.rb:187:in `run_proc'
/home/syed/.rvm/gems/ruby-1.9.2-p0/gems/delayed_job-3.0.3/lib/delayed/command.rb:87:in `run_process'
/home/syed/.rvm/gems/ruby-1.9.2-p0/gems/delayed_job-3.0.3/lib/delayed/command.rb:80:in `block in daemonize'
/home/syed/.rvm/gems/ruby-1.9.2-p0/gems/delayed_job-3.0.3/lib/delayed/command.rb:78:in `times'
/home/syed/.rvm/gems/ruby-1.9.2-p0/gems/delayed_job-3.0.3/lib/delayed/command.rb:78:in `daemonize'
script/delayed_job:5:in `<main>'"

这是处理程序:

"--- !ruby/object:Delayed::PerformableMailer 
args: 
- :activation_needed_email_method_name
- !ruby/ActiveRecord:Account 
  attributes: 
    id: 100
    username: student.ten@retinaindia.org
    email: student.ten@retinaindia.org
    crypted_password: !str:BCrypt::Password 
      str: $2a$10$ndL2tnPLheemvBsNqPXMwew6Pakf/Kf8xxt1Q54xkRWS3JfMaTAC6
      :@checksum: w6Pakf/Kf8xxt1Q54xkRWS3JfMaTAC6
      :@cost: 10
      :@salt: $2a$10$ndL2tnPLheemvBsNqPXMwe
      :@version: !str:BCrypt::Password 2a
    salt: Aatzxp2m4fp2CYy9ZoCr
    user_id: 74
    user_type: Student
    created_at: &id001 2012-07-09 08:34:23.981292 Z
    updated_at: *id001
    remember_me_token: 
    remember_me_token_expires_at: 
    reset_password_token: 
    reset_password_token_expires_at: 
    reset_password_email_sent_at: 
    failed_logins_count: 0
    lock_expires_at: 
    unlock_token: 
    last_login_at: 
    last_logout_at: 
    last_activity_at: 
    activation_state: pending
    activation_token: 7XAssTaEqsorDWpbpUY9
    activation_token_expires_at: 
    created_by: Admin
method_name: :send
object: !ruby/class UserMailer
"

[编辑] 无法执行 YAML.load 时会引发此错误。但是,奇怪的是,当我尝试在控制台中手动执行此操作时,它会加载任何问题。

ruby-1.9.2-p0 > YAML.load("--- !ruby/object:Delayed::PerformableMailer 
ruby-1.9.2-p0"> args: 
ruby-1.9.2-p0"> - !ruby/ActiveRecord:Account 
ruby-1.9.2-p0">   attributes: 
ruby-1.9.2-p0">     id: 106
ruby-1.9.2-p0">     username: student.two@retinaindia.org
ruby-1.9.2-p0">     email: student.two@retinaindia.org
ruby-1.9.2-p0">     crypted_password: !str:BCrypt::Password 
ruby-1.9.2-p0">       str: $2a$10$przMrMWjJqTetGj4IhLsEO9AjM12rnTuP2ZiJwz1xzSgr70dvJdM2
ruby-1.9.2-p0">       :@checksum: 9AjM12rnTuP2ZiJwz1xzSgr70dvJdM2
ruby-1.9.2-p0">       :@cost: 10
ruby-1.9.2-p0">       :@salt: $2a$10$przMrMWjJqTetGj4IhLsEO
ruby-1.9.2-p0">       :@version: !str:BCrypt::Password 2a
ruby-1.9.2-p0">     salt: f5CppR8NySi4VEEFNcLT
ruby-1.9.2-p0">     user_id: 81
ruby-1.9.2-p0">     user_type: Student
ruby-1.9.2-p0">     created_at: &id001 2012-07-09 11:08:49.705831 Z
ruby-1.9.2-p0">     updated_at: *id001
ruby-1.9.2-p0">     remember_me_token: 
ruby-1.9.2-p0">     remember_me_token_expires_at: 
ruby-1.9.2-p0">     reset_password_token: 
ruby-1.9.2-p0">     reset_password_token_expires_at: 
ruby-1.9.2-p0">     reset_password_email_sent_at: 
ruby-1.9.2-p0">     failed_logins_count: 0
ruby-1.9.2-p0">     lock_expires_at: 
ruby-1.9.2-p0">     unlock_token: 
ruby-1.9.2-p0">     last_login_at: 
ruby-1.9.2-p0">     last_logout_at: 
ruby-1.9.2-p0">     last_activity_at: 
ruby-1.9.2-p0">     activation_state: pending
ruby-1.9.2-p0">     activation_token: YZWfZBoGZj2qC6sVHsbQ
ruby-1.9.2-p0">     activation_token_expires_at: 
ruby-1.9.2-p0">     created_by: Self
ruby-1.9.2-p0"> method_name: :activation_needed_email
ruby-1.9.2-p0"> object: !ruby/class Notifier
ruby-1.9.2-p0"> ")
  Account Load (2.4ms)  SELECT "accounts".* FROM "accounts" WHERE "accounts"."id" = $1 LIMIT 1  [["id", 106]]
 => #<Delayed::PerformableMailer:0x9b39a08 @args=[#<Account id: 106, username: "student.two@retinaindia.org", email: "student.two@retinaindia.org", crypted_password: "$2a$10$przMrMWjJqTetGj4IhLsEO9AjM12rnTuP2ZiJwz1xzSg...", salt: "f5CppR8NySi4VEEFNcLT", user_id: 81, user_type: "Student", created_at: "2012-07-09 11:08:49", updated_at: "2012-07-09 11:08:49", remember_me_token: nil, remember_me_token_expires_at: nil, reset_password_token: nil, reset_password_token_expires_at: nil, reset_password_email_sent_at: nil, failed_logins_count: 0, lock_expires_at: nil, unlock_token: nil, last_login_at: nil, last_logout_at: nil, last_activity_at: nil, activation_state: "pending", activation_token: "YZWfZBoGZj2qC6sVHsbQ", activation_token_expires_at: nil, created_by: "Self">], @method_name=:activation_needed_email, @object=Notifier>
4

1 回答 1

1

回答我自己的问题,因为以下方法至少现在对我有用。

  1. 在delayed_job_config.rb 中需要'bcrypt'

require "bcrypt"

if defined?(BCrypt)
  puts "BCrypt defined."
else
  puts "BCrypt failed loaded!!"
end

Delayed::Worker.destroy_failed_jobs = false

2. 仍然无法让Sorcery 的user_activation 模块工作并通过delayed_job 自动发送电子邮件。必须完全禁用该模块并手动发送激活邮件。

于 2012-07-09T14:41:56.783 回答