0

我有一个分类模型,我使用 after_create 回调来检查用户的关键字并发送电子邮件通知。

此电子邮件由后台作业使用 ActiveJobs 和 Sucker_punch 作为后台驱动程序发送。

我在日志中看到 3 个作业正在排队:

[ActiveJob] Enqueued ActionMailer::DeliveryJob (Job ID: 8843b126-18fe-4cc1-b2f3-41141a199bcb) to SuckerPunch(mailers) with arguments: "NotificationMailer", "keyword_found", "deliver_now", gid://clasificados/Classified/233, gid://clasificados/User/1

[ActiveJob] Enqueued ActionMailer::DeliveryJob (Job ID: 591ce6eb-34d1-4381-93ea-4b708171996f) to SuckerPunch(mailers) with arguments: "NotificationMailer", "keyword_found", "deliver_now", gid://clasificados/Classified/234, gid://clasificados/User/1

[ActiveJob] Enqueued ActionMailer::DeliveryJob (Job ID: 3b1de0ea-f48d-41f2-be5a-8f5b2369b8ea) to SuckerPunch(mailers) with arguments: "NotificationMailer", "keyword_found", "deliver_now", gid://clasificados/Classified/235, gid://clasificados/User/1

但我只收到了2封电子邮件...

我在日志中看到如下错误:

Terminating 6 actors...
Terminating task: type=:finalizer, meta={:method_name=>:__shutdown__}, status=:receiving
    Celluloid::TaskFiber backtrace unavailable. Please try `Celluloid.task_class = Celluloid::TaskThread` if you need backtraces here.`

Terminating task: type=:call, meta={:method_name=>:perform}, status=:callwait
    Celluloid::TaskFiber backtrace unavailable. Please try `Celluloid.task_class = Celluloid::TaskThread` if you need backtraces here.
Celluloid::PoolManager: async call `perform` aborted!
Celluloid::Task::TerminatedError: task was terminated
    /home/angel/.gem/ruby/2.2.2/gems/celluloid-0.16.0/lib/celluloid/tasks/task_fiber.rb:34:in `terminate'
    /home/angel/.gem/ruby/2.2.2/gems/celluloid-0.16.0/lib/celluloid/actor.rb:345:in `each'
    /home/angel/.gem/ruby/2.2.2/gems/celluloid-0.16.0/lib/celluloid/actor.rb:345:in `cleanup'
    /home/angel/.gem/ruby/2.2.2/gems/celluloid-0.16.0/lib/celluloid/actor.rb:329:in `shutdown'
    /home/angel/.gem/ruby/2.2.2/gems/celluloid-0.16.0/lib/celluloid/actor.rb:164:in `run'
    /home/angel/.gem/ruby/2.2.2/gems/celluloid-0.16.0/lib/celluloid/actor.rb:130:in `block in start'
    /home/angel/.gem/ruby/2.2.2/gems/celluloid-0.16.0/lib/celluloid/thread_handle.rb:13:in `block in initialize'
    /home/angel/.gem/ruby/2.2.2/gems/celluloid-0.16.0/lib/celluloid/actor_system.rb:32:in `block in get_thread'
    /home/angel/.gem/ruby/2.2.2/gems/celluloid-0.16.0/lib/celluloid/internal_pool.rb:130:in `call'
    /home/angel/.gem/ruby/2.2.2/gems/celluloid-0.16.0/lib/celluloid/internal_pool.rb:130:in `block in create'
Terminating task: type=:call, meta={:method_name=>:perform}, status=:callwait
    Celluloid::TaskFiber backtrace unavailable. Please try `Celluloid.task_class = Celluloid::TaskThread` if you need backtraces here.
Celluloid::PoolManager: async call `perform` aborted!
Celluloid::Task::TerminatedError: task was terminated
    /home/angel/.gem/ruby/2.2.2/gems/celluloid-0.16.0/lib/celluloid/tasks/task_fiber.rb:34:in `terminate'
    /home/angel/.gem/ruby/2.2.2/gems/celluloid-0.16.0/lib/celluloid/actor.rb:345:in `each'
    /home/angel/.gem/ruby/2.2.2/gems/celluloid-0.16.0/lib/celluloid/actor.rb:345:in `cleanup'
    /home/angel/.gem/ruby/2.2.2/gems/celluloid-0.16.0/lib/celluloid/actor.rb:329:in `shutdown'
    /home/angel/.gem/ruby/2.2.2/gems/celluloid-0.16.0/lib/celluloid/actor.rb:164:in `run'
    /home/angel/.gem/ruby/2.2.2/gems/celluloid-0.16.0/lib/celluloid/actor.rb:130:in `block in start'
    /home/angel/.gem/ruby/2.2.2/gems/celluloid-0.16.0/lib/celluloid/thread_handle.rb:13:in `block in initialize'
    /home/angel/.gem/ruby/2.2.2/gems/celluloid-0.16.0/lib/celluloid/actor_system.rb:32:in `block in get_thread'
    /home/angel/.gem/ruby/2.2.2/gems/celluloid-0.16.0/lib/celluloid/internal_pool.rb:130:in `call'
    /home/angel/.gem/ruby/2.2.2/gems/celluloid-0.16.0/lib/celluloid/internal_pool.rb:130:in `block in create'
Terminating task: type=:finalizer, meta={:method_name=>:__shutdown__}, status=:receiving
    Celluloid::TaskFiber backtrace unavailable. Please try `Celluloid.task_class = Celluloid::TaskThread` if you need backtraces here.

模型:

class Classified < ActiveRecord::Base

  after_create :find_matched_keywords

  def find_matched_keywords
    User.all.each do |u|
      u.profile.keywords.scan(/[a-zA-Z\d]+/) do |k|
        if self[:content].downcase.include?(k)
          SendEmailJob.new.async.perform(self, u)
          break
        end
      end
    end
  end

end

工作:

class SendEmailJob < ActiveJob::Base
  include SuckerPunch::Job
  queue_as :default

  def perform(classified, user)
    NotificationMailer.keyword_found(classified, user).deliver_later
  end
end

知道会发生什么吗?

先谢谢了

4

1 回答 1

1

好吧,我改成了sidekiq ...问题解决了。

于 2015-06-09T21:50:46.917 回答