more intelligent queuing of async jobs
This commit is contained in:
@@ -17,7 +17,7 @@ class LegacyController < ApplicationController
|
|||||||
@upload.rating = params[:post][:rating][0].downcase
|
@upload.rating = params[:post][:rating][0].downcase
|
||||||
@upload.md5_confirmation = params[:md5] if params[:md5].present?
|
@upload.md5_confirmation = params[:md5] if params[:md5].present?
|
||||||
@upload.save
|
@upload.save
|
||||||
@upload.delay.process!
|
@upload.process!
|
||||||
end
|
end
|
||||||
|
|
||||||
def users
|
def users
|
||||||
|
|||||||
@@ -622,6 +622,8 @@ class Post < ActiveRecord::Base
|
|||||||
|
|
||||||
if tags.blank? && Danbooru.config.blank_tag_search_fast_count
|
if tags.blank? && Danbooru.config.blank_tag_search_fast_count
|
||||||
count = 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}):/
|
elsif tags =~ /(?:#{Tag::METATAGS}):/
|
||||||
count = fast_count_search(tags)
|
count = fast_count_search(tags)
|
||||||
else
|
else
|
||||||
|
|||||||
@@ -81,17 +81,15 @@ class Tag < ActiveRecord::Base
|
|||||||
end
|
end
|
||||||
|
|
||||||
def update_category_cache_for_all
|
def update_category_cache_for_all
|
||||||
Danbooru.config.all_server_hosts.each do |host|
|
if category_changed?
|
||||||
delay.update_category_cache(host)
|
Danbooru.config.all_server_hosts.each do |host|
|
||||||
|
delay(:queue => host).update_category_cache
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def update_category_cache(host)
|
def update_category_cache
|
||||||
if host == Socket.gethostname
|
Cache.put("tc:#{Cache.sanitize(name)}", category, 1.hour)
|
||||||
Cache.put("tc:#{Cache.sanitize(name)}", category, 1.hour)
|
|
||||||
else
|
|
||||||
delay.update_category_cache(host)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -371,7 +369,13 @@ class Tag < ActiveRecord::Base
|
|||||||
end
|
end
|
||||||
|
|
||||||
def update_related_if_outdated
|
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
|
end
|
||||||
|
|
||||||
def related_cache_expiry
|
def related_cache_expiry
|
||||||
@@ -386,7 +390,7 @@ class Tag < ActiveRecord::Base
|
|||||||
end
|
end
|
||||||
|
|
||||||
def should_update_related?
|
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
|
end
|
||||||
|
|
||||||
def related_tag_array
|
def related_tag_array
|
||||||
|
|||||||
@@ -88,16 +88,12 @@ class TagAlias < ActiveRecord::Base
|
|||||||
|
|
||||||
def clear_all_cache
|
def clear_all_cache
|
||||||
Danbooru.config.all_server_hosts.each do |host|
|
Danbooru.config.all_server_hosts.each do |host|
|
||||||
delay.clear_cache(host)
|
delay(:queue => host).clear_cache(host)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def clear_cache(host = Socket.gethostname)
|
def clear_cache(host = Socket.gethostname)
|
||||||
if host == Socket.gethostname
|
Cache.delete("ta:#{Cache.sanitize(antecedent_name)}")
|
||||||
Cache.delete("ta:#{Cache.sanitize(antecedent_name)}")
|
|
||||||
else
|
|
||||||
delay.clear_cache(host)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def update_cache
|
def update_cache
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ class Upload < ActiveRecord::Base
|
|||||||
before_create :convert_cgi_file
|
before_create :convert_cgi_file
|
||||||
after_destroy :delete_temp_file
|
after_destroy :delete_temp_file
|
||||||
validate :uploader_is_not_limited
|
validate :uploader_is_not_limited
|
||||||
validate :file_or_source_is_present
|
validate :file_or_source_is_present, :on => :create
|
||||||
|
|
||||||
module ValidationMethods
|
module ValidationMethods
|
||||||
def uploader_is_not_limited
|
def uploader_is_not_limited
|
||||||
@@ -65,11 +65,6 @@ class Upload < ActiveRecord::Base
|
|||||||
def process! force=false
|
def process! force=false
|
||||||
return if !force && status =~ /processing|completed|error/
|
return if !force && status =~ /processing|completed|error/
|
||||||
|
|
||||||
if server != Socket.gethostname
|
|
||||||
delay.process!
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
CurrentUser.scoped(uploader, uploader_ip_addr) do
|
CurrentUser.scoped(uploader, uploader_ip_addr) do
|
||||||
update_attribute(:status, "processing")
|
update_attribute(:status, "processing")
|
||||||
if is_downloadable?
|
if is_downloadable?
|
||||||
|
|||||||
@@ -168,7 +168,7 @@ module Danbooru
|
|||||||
|
|
||||||
# Names of other Danbooru servers.
|
# Names of other Danbooru servers.
|
||||||
def other_server_hosts
|
def other_server_hosts
|
||||||
all_server_hosts.reject {|x| x == server_host}
|
@other_server_hosts ||= all_server_hosts.reject {|x| x == server_host}
|
||||||
end
|
end
|
||||||
|
|
||||||
def remote_server_login
|
def remote_server_login
|
||||||
|
|||||||
@@ -105,7 +105,7 @@ end
|
|||||||
namespace :delayed_job do
|
namespace :delayed_job do
|
||||||
desc "Start delayed_job process"
|
desc "Start delayed_job process"
|
||||||
task :start, :roles => :app do
|
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
|
end
|
||||||
|
|
||||||
desc "Stop delayed_job process"
|
desc "Stop delayed_job process"
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ FactoryGirl.define do
|
|||||||
tag_string "special"
|
tag_string "special"
|
||||||
status "pending"
|
status "pending"
|
||||||
server Socket.gethostname
|
server Socket.gethostname
|
||||||
|
source "xxx"
|
||||||
|
|
||||||
factory(:source_upload) do
|
factory(:source_upload) do
|
||||||
source "http://www.google.com/intl/en_ALL/images/logo.gif"
|
source "http://www.google.com/intl/en_ALL/images/logo.gif"
|
||||||
|
|||||||
Reference in New Issue
Block a user