This commit is contained in:
r888888888
2015-11-19 16:32:15 -08:00
parent 1288889e52
commit 9d3ecee741
2 changed files with 61 additions and 23 deletions

View File

@@ -82,20 +82,31 @@ class TagAlias < ActiveRecord::Base
raise errors.full_messages.join("; ")
end
admin = CurrentUser.user || User.admins.first
CurrentUser.scoped(admin, "127.0.0.1") do
update_column(:status, "processing")
move_aliases_and_implications
clear_all_cache
ensure_category_consistency
update_posts
update_forum_topic_for_approve if update_topic
update_column(:post_count, consequent_tag.post_count)
update_column(:status, "active")
tries = 0
begin
admin = CurrentUser.user || User.admins.first
CurrentUser.scoped(admin, "127.0.0.1") do
update_column(:status, "processing")
move_aliases_and_implications
clear_all_cache
ensure_category_consistency
update_posts
update_forum_topic_for_approve if update_topic
update_column(:post_count, consequent_tag.post_count)
update_column(:status, "active")
end
rescue Exception => e
if tries < 5
tries += 1
sleep 2 ** tries
retry
end
update_forum_topic_for_error(e)
update_column(:status, "error: #{e}")
NewRelic::Agent.notice_error(e, :custom_params => {:tag_alias_id => id, :antecedent_name => antecedent_name, :consequent_name => consequent_name})
end
rescue Exception => e
update_column(:status, "error: #{e}")
NewRelic::Agent.notice_error(e, :custom_params => {:tag_alias_id => id, :antecedent_name => antecedent_name, :consequent_name => consequent_name})
end
def is_pending?
@@ -246,6 +257,14 @@ class TagAlias < ActiveRecord::Base
end
end
def update_forum_topic_for_error(e)
if forum_topic
forum_topic.posts.create(
:body => "The tag alias #{antecedent_name} -> #{consequent_name} failed during processing. Reason: #{e}"
)
end
end
def update_forum_topic_for_reject
if forum_topic
forum_topic.posts.create(

View File

@@ -125,17 +125,28 @@ class TagImplication < ActiveRecord::Base
raise errors.full_messages.join("; ")
end
admin = CurrentUser.user || User.admins.first
CurrentUser.scoped(admin, "127.0.0.1") do
update_column(:status, "processing")
update_posts
update_column(:status, "active")
update_descendant_names_for_parents
update_forum_topic_for_approve if update_topic
tries = 0
begin
admin = CurrentUser.user || User.admins.first
CurrentUser.scoped(admin, "127.0.0.1") do
update_column(:status, "processing")
update_posts
update_column(:status, "active")
update_descendant_names_for_parents
update_forum_topic_for_approve if update_topic
end
rescue Exception => e
if tries < 5
tries += 1
sleep 2 ** tries
retry
end
update_forum_topic_for_error(e)
update_column(:status, "error: #{e}")
NewRelic::Agent.notice_error(e, :custom_params => {:tag_implication_id => id, :antecedent_name => antecedent_name, :consequent_name => consequent_name})
end
rescue Exception => e
update_column(:status, "error: #{e}")
NewRelic::Agent.notice_error(e, :custom_params => {:tag_implication_id => id, :antecedent_name => antecedent_name, :consequent_name => consequent_name})
end
def absence_of_circular_relation
@@ -237,6 +248,14 @@ class TagImplication < ActiveRecord::Base
end
end
def update_forum_topic_for_error(e)
if forum_topic
forum_topic.posts.create(
:body => "The tag implication #{antecedent_name} -> #{consequent_name} failed during processing. Reason: #{e}"
)
end
end
def reject!
update_forum_topic_for_reject
destroy