make tag subscription updates asynchronous
This commit is contained in:
@@ -151,18 +151,20 @@ class TagSubscription < ActiveRecord::Base
|
|||||||
arel.order("id DESC").limit(limit)
|
arel.order("id DESC").limit(limit)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.process(id)
|
||||||
|
tag_subscription = TagSubscription.find(id)
|
||||||
|
CurrentUser.scoped(tag_subscription.creator, "127.0.0.1") do
|
||||||
|
tag_subscription.process
|
||||||
|
tag_subscription.save
|
||||||
|
end
|
||||||
|
rescue Exception => x
|
||||||
|
raise if Rails.env != "production"
|
||||||
|
end
|
||||||
|
|
||||||
def self.process_all
|
def self.process_all
|
||||||
find_each do |tag_subscription|
|
find_each do |tag_subscription|
|
||||||
CurrentUser.scoped(tag_subscription.creator, "127.0.0.1") do
|
if tag_subscription.creator.is_gold? && tag_subscription.is_active?
|
||||||
if $job_task_daemon_active != false && tag_subscription.creator.is_gold? && tag_subscription.is_active?
|
TagSubscription.delay(:queue => "default").process(tag_subscription.id)
|
||||||
begin
|
|
||||||
tag_subscription.process
|
|
||||||
tag_subscription.save
|
|
||||||
sleep 0
|
|
||||||
rescue Exception => x
|
|
||||||
raise if Rails.env != "production"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ class TagSubscriptionTest < ActiveSupport::TestCase
|
|||||||
user = FactoryGirl.create(:user)
|
user = FactoryGirl.create(:user)
|
||||||
CurrentUser.user = user
|
CurrentUser.user = user
|
||||||
CurrentUser.ip_addr = "127.0.0.1"
|
CurrentUser.ip_addr = "127.0.0.1"
|
||||||
|
Delayed::Worker.delay_jobs = false
|
||||||
MEMCACHE.flush_all
|
MEMCACHE.flush_all
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user