0

我正在尝试从控制器方法运行 ActiveJob 作业,但它失败了,我无法找到问题的正确位置:

#app/controllers/users_controller.rb

1   class UsersController < ApplicationController
2       def new
3         @user = User.new
4       end1 
5   
6     def create
7       @user = User.create(user_params)
8       PoliciesChecksJob.new(@user.id).enqueue
9       # redirect to somewhere
10   end1 
11  end

#app/jobs/policies_checks_job.rb

class PoliciesChecksJob < ActiveJob::Base
  queue_as :default

  def perform(user_id)
    SearchPoliciesCommands.new.execute(user_id)
  end
end

日志摘要:

Started POST "/users" for ::1 at 2015-03-30 15:01:03 +0100 
Processing by UsersController#create as HTML
...(params)
(0.1ms)  BEGIN
... (inserts the user)
(0.3ms)  COMMIT 
[ActiveJob] Enqueued PoliciesChecksJob (Job ID: da...e2) to Sneakers(default) with arguments: 1

Completed 500 Internal Server Error in 76ms

NoMethodError (private method `warn' called for nil:NilClass):   
app/controllers/users_controller.rb:8:in `create'

我会很感激任何想法。

4

1 回答 1

0

基本上enqueue 适配器有一个小问题:我更喜欢使用Sneakers,因为它在RabbitMQ上工作得很好。

  1. 所以我必须指定我想要一个不同于默认的入队适配器:

#config/application.rb

config.active_job.queue_adapter = :sneakers 
  1. 安装RabbitMQ启动它:

    (最好在不同的终端选项卡中)

    $rabbitmq 服务器

  2. 安装 gem运动鞋并在(首选其他终端选项卡)中运行其守护进程:

$ 运动鞋工作 ActiveJob::QueueAdapters::SneakersAdapter::JobWrapper --require app/jobs/policies_checks_job.rb

于 2015-04-01T14:36:45.897 回答