more intelligent queuing of async jobs

This commit is contained in:
albert
2013-03-03 01:12:31 -05:00
parent b55d40e70a
commit f0b29fc3ba
8 changed files with 23 additions and 25 deletions

View File

@@ -17,7 +17,7 @@ class LegacyController < ApplicationController
@upload.rating = params[:post][:rating][0].downcase
@upload.md5_confirmation = params[:md5] if params[:md5].present?
@upload.save
@upload.delay.process!
@upload.process!
end
def users

View File

@@ -622,6 +622,8 @@ class Post < ActiveRecord::Base
if tags.blank? && Danbooru.config.blank_tag_search_fast_count
count = Danbooru.config.blank_tag_search_fast_count
elsif tags =~ /^rating:\S+$/
count = Danbooru.config.blank_tag_search_fast_count
elsif tags =~ /(?:#{Tag::METATAGS}):/
count = fast_count_search(tags)
else

View File

@@ -81,17 +81,15 @@ class Tag < ActiveRecord::Base
end
def update_category_cache_for_all
Danbooru.config.all_server_hosts.each do |host|
delay.update_category_cache(host)
if category_changed?
Danbooru.config.all_server_hosts.each do |host|
delay(:queue => host).update_category_cache
end
end
end
def update_category_cache(host)
if host == Socket.gethostname
Cache.put("tc:#{Cache.sanitize(name)}", category, 1.hour)
else
delay.update_category_cache(host)
end
def update_category_cache
Cache.put("tc:#{Cache.sanitize(name)}", category, 1.hour)
end
end
@@ -371,7 +369,13 @@ class Tag < ActiveRecord::Base
end
def update_related_if_outdated
delay.update_related if should_update_related?
if should_update_related?
if post_count < 100
update_related
else
delay.update_related
end
end
end
def related_cache_expiry
@@ -386,7 +390,7 @@ class Tag < ActiveRecord::Base
end
def should_update_related?
Delayed::Job.count < 200 && related_tags.blank? || related_tags_updated_at.blank? || related_tags_updated_at < related_cache_expiry.hours.ago
Delayed::Job.count < 200 && (related_tags.blank? || related_tags_updated_at.blank? || related_tags_updated_at < related_cache_expiry.hours.ago)
end
def related_tag_array

View File

@@ -88,16 +88,12 @@ class TagAlias < ActiveRecord::Base
def clear_all_cache
Danbooru.config.all_server_hosts.each do |host|
delay.clear_cache(host)
delay(:queue => host).clear_cache(host)
end
end
def clear_cache(host = Socket.gethostname)
if host == Socket.gethostname
Cache.delete("ta:#{Cache.sanitize(antecedent_name)}")
else
delay.clear_cache(host)
end
Cache.delete("ta:#{Cache.sanitize(antecedent_name)}")
end
def update_cache

View File

@@ -12,7 +12,7 @@ class Upload < ActiveRecord::Base
before_create :convert_cgi_file
after_destroy :delete_temp_file
validate :uploader_is_not_limited
validate :file_or_source_is_present
validate :file_or_source_is_present, :on => :create
module ValidationMethods
def uploader_is_not_limited
@@ -65,11 +65,6 @@ class Upload < ActiveRecord::Base
def process! force=false
return if !force && status =~ /processing|completed|error/
if server != Socket.gethostname
delay.process!
return
end
CurrentUser.scoped(uploader, uploader_ip_addr) do
update_attribute(:status, "processing")
if is_downloadable?

View File

@@ -168,7 +168,7 @@ module Danbooru
# Names of other Danbooru servers.
def other_server_hosts
all_server_hosts.reject {|x| x == server_host}
@other_server_hosts ||= all_server_hosts.reject {|x| x == server_host}
end
def remote_server_login

View File

@@ -105,7 +105,7 @@ end
namespace :delayed_job do
desc "Start delayed_job process"
task :start, :roles => :app do
run "cd #{current_path}; RAILS_ENV=#{rails_env} bundle exec ruby script/delayed_job start"
run "cd #{current_path}; RAILS_ENV=#{rails_env} bundle exec ruby script/delayed_job --queue=`hostname` start"
end
desc "Stop delayed_job process"

View File

@@ -8,6 +8,7 @@ FactoryGirl.define do
tag_string "special"
status "pending"
server Socket.gethostname
source "xxx"
factory(:source_upload) do
source "http://www.google.com/intl/en_ALL/images/logo.gif"