increse timeouts for delayed job actions

This commit is contained in:
albert
2013-03-31 23:40:06 -04:00
parent ea7df25079
commit 88a900ac9e
3 changed files with 11 additions and 7 deletions

View File

@@ -1,7 +1,9 @@
class RelatedTagCalculator class RelatedTagCalculator
def self.find_tags(tag, limit) def self.find_tags(tag, limit)
Post.with_timeout(10_000) do
Post.tag_match(tag).limit(limit).select("posts.tag_string").reorder("posts.md5").map(&:tag_string) Post.tag_match(tag).limit(limit).select("posts.tag_string").reorder("posts.md5").map(&:tag_string)
end end
end
def self.calculate_from_sample_to_array(tags, category_constraint = nil) def self.calculate_from_sample_to_array(tags, category_constraint = nil)
convert_hash_to_array(calculate_from_sample(tags, Danbooru.config.post_sample_size, category_constraint)) convert_hash_to_array(calculate_from_sample(tags, Danbooru.config.post_sample_size, category_constraint))

View File

@@ -100,6 +100,7 @@ class Tag < ActiveRecord::Base
Post.raw_tag_match(name).find_each do |post| Post.raw_tag_match(name).find_each do |post|
post.reload post.reload
post.set_tag_counts post.set_tag_counts
Post.with_timeout(10_000, nil) do
post.update_column(:tag_count, post.tag_count) post.update_column(:tag_count, post.tag_count)
post.update_column(:tag_count_general, post.tag_count_general) post.update_column(:tag_count_general, post.tag_count_general)
post.update_column(:tag_count_artist, post.tag_count_artist) post.update_column(:tag_count_artist, post.tag_count_artist)
@@ -107,6 +108,7 @@ class Tag < ActiveRecord::Base
post.update_column(:tag_count_character, post.tag_count_character) post.update_column(:tag_count_character, post.tag_count_character)
end end
end end
end
def update_category_cache def update_category_cache
Cache.put("tc:#{Cache.sanitize(name)}", category, 1.hour) Cache.put("tc:#{Cache.sanitize(name)}", category, 1.hour)

View File

@@ -11,7 +11,7 @@ module Danbooru
connection.execute("SET STATEMENT_TIMEOUT = #{CurrentUser.user.statement_timeout}") unless Rails.env == "test" connection.execute("SET STATEMENT_TIMEOUT = #{CurrentUser.user.statement_timeout}") unless Rails.env == "test"
end end
def with_timeout(n, default_value) def with_timeout(n, default_value = nil)
connection.execute("SET STATEMENT_TIMEOUT = #{n}") unless Rails.env == "test" connection.execute("SET STATEMENT_TIMEOUT = #{n}") unless Rails.env == "test"
yield yield
rescue ::ActiveRecord::StatementInvalid rescue ::ActiveRecord::StatementInvalid