简而言之,我收到一个错误,public_activity
正在寻找在工作current_user
期间更新模型时sidekiq
。这是意料之中的,因为没有current_user
....如何public_activity
在作业运行时禁用跟踪?我在工作期间尝试过改变PublicActivity.enabled = false
,Prospect.public_activity_off
但tracked owner: Proc.new{ |controller, model| controller.current_user }
似乎仍然在捡起它并寻找current_user
我怎样才能让sidekiq
(或任何工作)在不public_activity
干扰的情况下进行更新?
sidekiq
在工作期间将其设置current_user
为虚拟用户会更好吗?我认为这不是一个好主意,因为我们需要稍后将其过滤掉。
错误:
2016-04-20T17:24:53.728Z 20447 TID-owpsaw07w ProspectDataAggregationWorker JID-bad79ab6a073d57d7388e931 INFO: start
2016-04-20T17:24:53.739Z 20447 TID-owpsaw07w ProspectDataAggregationWorker JID-bad79ab6a073d57d7388e931 INFO: fail: 0.01 sec
2016-04-20T17:24:53.739Z 20447 TID-owpsaw07w WARN: {"class"=>"ProspectDataAggregationWorker", "args"=>[1], "retry"=>false, "queue"=>"default", "jid"=>"bad79ab6a073d57d7388e931", "created_at"=>1461173093.728181, "enqueued_at"=>1461173093.7282372}
2016-04-20T17:24:53.739Z 20447 TID-owpsaw07w WARN: NoMethodError: undefined method `current_user' for nil:NilClass
2016-04-20T17:24:53.739Z 20447 TID-owpsaw07w WARN: /Users/cj/RubymineProjects/revenue_management_system/app/models/prospect.rb:3:in `block in <class:Prospect>'
/Users/cj/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/public_activity-1.5.0/lib/public_activity/common.rb:14:in `resolve_value'
/Users/cj/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/public_activity-1.5.0/lib/public_activity/common.rb:315:in `prepare_relation'
/Users/cj/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/public_activity-1.5.0/lib/public_activity/common.rb:281:in `prepare_settings'
/Users/cj/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/public_activity-1.5.0/lib/public_activity/common.rb:250:in `create_activity'
/Users/cj/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/public_activity-1.5.0/lib/public_activity/actions/update.rb:14:in `activity_on_update'
/Users/cj/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/activesupport-4.2.6/lib/active_support/callbacks.rb:432:in `block in make_lambda'
完全错误:https ://gist.github.com/cdesch/190c46c69213a37e4162e50727531761
模型:
class Prospect < ActiveRecord::Base
include PublicActivity::Model
tracked owner: Proc.new{ |controller, model| controller.current_user }
...
end
Sidekiq 工作/工人
class ProspectDataAggregationWorker
include Sidekiq::Worker
sidekiq_options :retry => false # job will be discarded immediately if failed
def perform(account_id)
#Prospect.public_activity_off
PublicActivity.enabled = false
account = Account.where(id: account_id).first
prospects = account.prospects
prospects.each do |prospect|
prospect.update_based_on_primary_assessment!
end
PublicActivity.enabled = true
#Prospect.public_activity_on
end
end