Use resque-schedule for cleanup

This commit is contained in:
Vokhmin Alexey V 2014-02-25 00:36:51 +04:00
parent 8d178b856f
commit fe20a9788a
10 changed files with 58 additions and 27 deletions

View File

@ -0,0 +1,8 @@
class BuildListsPublishTaskManagerJob
@queue = :hook
def self.perform
AbfWorker::BuildListsPublishTaskManager.new.run
end
end

View File

@ -0,0 +1,18 @@
class CleanBuildListsQueuesJob
@queue = :hook
def self.perform
redis = Resque.redis
redis.smembers('queues').each do |key|
next if key !~ /(user|mass)_build_/
queue = "queue:#{key}"
if redis.llen(queue) == 0
redis.multi do
redis.del queue
redis.srem 'queues', key
end
end
end
end
end

View File

@ -0,0 +1,10 @@
class CleanRpmBuildNodeJob
@queue = :hook
def self.perform
RpmBuildNode.all.each do |n|
n.delete unless n.user_id
end
end
end

View File

@ -558,7 +558,6 @@ class BuildList < ActiveRecord::Base
if task
build_list = BuildList.where(id: task['args'][0]['id']).first
build_list.cleanup_build_sets
build_list.delayed_add_job_to_abf_worker_queue
build_list
end

View File

@ -17,12 +17,6 @@ class RpmBuildNode < Ohm::Model
User.where(id: user_id).first
end
def self.cleanup!
RpmBuildNode.all.each do |n|
n.delete unless n.user_id
end
end
def self.total_statistics
systems, others, busy = 0, 0, 0
RpmBuildNode.all.select{ |n| n.user_id }.each do |n|

View File

@ -27,6 +27,7 @@ module Rosa
# Custom directories with classes and modules you want to be autoloadable.
# config.autoload_paths += %W(#{config.root}/extras)
config.autoload_paths += %W(#{config.root}/app/presenters)
config.autoload_paths += %W(#{config.root}/app/jobs)
# Only load the plugins named here, in the order given (default is alphabetical).
# :all can be used as a placeholder for all plugins not explicitly named.

View File

@ -10,6 +10,7 @@ Resque::Mailer.excluded_environments = [:test]
unless Rails.env.test?
PerformLater.config.enabled = true # this will default to false if unset
Resque.schedule = YAML.load_file(File.join(Rails.root, 'config/resque_schedule.yml')) # load the schedule
end
Resque::Plugins::Status::Hash.expire_in = (24 * 60 * 60) # 24hrs in seconds

View File

@ -0,0 +1,20 @@
clean_rpm_build_nodes:
every:
- '1m'
class: 'CleanRpmBuildNodeJob'
queue: hook
description: 'Cleans RPM build nodes'
build_lists_publish_task_manager:
every:
- '3m'
class: 'BuildListsPublishTaskManagerJob'
queue: hook
description: 'Creates tasks for publishing'
clean_build_lists_queues:
every:
- '1m'
class: 'CleanBuildListsQueuesJob'
queue: hook
description: 'Cleans build_lists queues'

View File

@ -26,14 +26,6 @@ every :day, at: '3:00 am' do
rake 'activity_feeds:clear', output: 'log/activity_feeds.log'
end
every 3.minute do
runner 'AbfWorker::BuildListsPublishTaskManager.new.run', output: 'log/task_manager.log'
end
every 1.minute do
runner 'RpmBuildNode.cleanup!'
end
every 1.hour do
rake 'buildlist:clear:outdated_canceling', output: 'log/canceling_build_list_clear.log'
end

View File

@ -58,7 +58,6 @@ module AbfWorker::ModelHelper
worker_queue_class,
abf_worker_args
)
cleanup_build_sets
result
end
@ -82,17 +81,6 @@ module AbfWorker::ModelHelper
"AbfWorker::#{abf_worker_base_queue.classify}#{abf_worker_priority.capitalize}"
end
def cleanup_build_sets
return unless is_a?(BuildList)
queue = worker_queue_with_priority
if Resque.redis.llen("queue:#{queue}") == 0
key = mass_build_id ? MASS_BUILDS_SET : USER_BUILDS_SET
Resque.redis.srem key, mass_build_id || user_id
Resque.redis.del "queue:#{queue}"
Resque.redis.srem 'queues', queue
end
end
private