Skip to content
Browse files

Fix an issue with workers not queueing jobs

Signed-off-by: David Celis <david@davidcelis.com>
  • Loading branch information...
1 parent 42ae845 commit e706631c94a0974d863198da955b859e3115e292 @davidcelis committed
View
2 lib/recommendable.rb
@@ -33,7 +33,7 @@ def enqueue(user_id)
Delayed::Job.enqueue(Recommendable::Workers::DelayedJob.new(user_id))
elsif defined?(::Rails::Queueing)
unless Rails.queue.any? { |w| w.user_id == user_id }
- Rails.queue.push(Recommendable::Workers::Rails.new(user_idid))
+ Rails.queue.push(Recommendable::Workers::Rails.new(user_id))
Rails.application.queue_consumer.start
end
end
View
1 lib/recommendable/helpers/calculations.rb
@@ -84,6 +84,7 @@ def update_recommendations_for(user_id)
sets << Recommendable::Helpers::RedisKeyMapper.liked_set_for(klass, id)
end
+ return if sets_to_union.empty?
scores = Recommendable.redis.sunion(sets_to_union).map { |id| [predict_for(user_id, klass, id), id] }
scores.each do |s|
Recommendable.redis.zadd(recommended_set, s[0], s[1])
View
18 lib/recommendable/workers/delayed_job.rb
@@ -1,17 +1,15 @@
module Recommendable
module Workers
- if defined?(Delayed::Job)
- class DelayedJob
- attr_accessor :user_id
+ class DelayedJob
+ attr_accessor :user_id
- def initialize(user_id)
- @user_id = user_id
- end
+ def initialize(user_id)
+ @user_id = user_id
+ end
- def perform
- Recommendable::Helpers::Calculations.update_similarities_for(user_id)
- Recommendable::Helpers::Calculations.update_recommendations_for(user_id)
- end
+ def perform
+ Recommendable::Helpers::Calculations.update_similarities_for(user_id)
+ Recommendable::Helpers::Calculations.update_recommendations_for(user_id)
end
end
end
View
18 lib/recommendable/workers/rails.rb
@@ -1,17 +1,15 @@
module Recommendable
module Workers
- if defined?(Rails::Queueing)
- class Rails
- attr_accessor :user_id
+ class Rails
+ attr_accessor :user_id
- def initialize(user_id)
- @user_id = user_id
- end
+ def initialize(user_id)
+ @user_id = user_id
+ end
- def run
- Recommendable::Helpers::Calculations.update_similarities_for(user_id)
- Recommendable::Helpers::Calculations.update_recommendations_for(user_id)
- end
+ def run
+ Recommendable::Helpers::Calculations.update_similarities_for(user_id)
+ Recommendable::Helpers::Calculations.update_recommendations_for(user_id)
end
end
end
View
14 lib/recommendable/workers/resque.rb
@@ -1,14 +1,12 @@
module Recommendable
module Workers
- if defined?(Resque)
- class Resque
- include ::Resque::Plugins::UniqueJob if defined?(::Resque::Plugins::UniqueJob)
- @queue = :recommendable
+ class Resque
+ include ::Resque::Plugins::UniqueJob if defined?(::Resque::Plugins::UniqueJob)
+ @queue = :recommendable
- def self.perform(user_id)
- Recommendable::Helpers::Calculations.update_similarities_for(user_id)
- Recommendable::Helpers::Calculations.update_recommendations_for(user_id)
- end
+ def self.perform(user_id)
+ Recommendable::Helpers::Calculations.update_similarities_for(user_id)
+ Recommendable::Helpers::Calculations.update_recommendations_for(user_id)
end
end
end
View
12 lib/recommendable/workers/sidekiq.rb
@@ -1,14 +1,14 @@
module Recommendable
module Workers
- if defined?(Sidekiq)
- class Sidekiq
+ class Sidekiq
+ if defined?(::Sidekiq)
include ::Sidekiq::Worker
sidekiq_options :unique => true, :queue => :recommendable
+ end
- def perform(user_id)
- Recommendable::Helpers::Calculations.update_similarities_for(user_id)
- Recommendable::Helpers::Calculations.update_recommendations_for(user_id)
- end
+ def perform(user_id)
+ Recommendable::Helpers::Calculations.update_similarities_for(user_id)
+ Recommendable::Helpers::Calculations.update_recommendations_for(user_id)
end
end
end

0 comments on commit e706631

Please sign in to comment.
Something went wrong with that request. Please try again.