我正在尝试从控制器方法运行ActiveJob作业,但它失败了,我无法找到问题的正确位置:
#应用程序/控制器/ 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
#应用程序/任务/ 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'
我很感激任何想法。
答案 0 :(得分:0)
排队适配器基本上存在一些问题: 我更喜欢使用Sneakers,因为它可以与RabbitMQ一起使用。
<强>#配置/ application.rb中强>
config.active_job.queue_adapter = :sneakers
安装 RabbitMQ ,然后开始:
(在不同的终端标签中更喜欢)
$ rabbitmq-server
在(首选其他终端标签)中安装运动鞋和运行其守护程序:
$ sneakers work ActiveJob :: QueueAdapters :: SneakersAdapter :: JobWrapper --require app / jobs / policies_checks_job.rb