Configure resque-scheduler gem

This commit is contained in:
Vokhmin Alexey V 2014-02-10 23:36:10 +04:00
parent 8402728f4d
commit e889f23660
7 changed files with 70 additions and 8 deletions

View File

@ -18,7 +18,9 @@ gem 'paperclip', '~> 3.3.1'
gem 'resque', '~> 1.24'
gem 'resque-status', '~> 0.3.3'
gem 'resque_mailer', '~> 2.2'
gem 'perform_later', '~> 1.3.0' # should be after resque_mailer
gem 'resque-scheduler'
# gem 'perform_later', '~> 1.3.0' # should be after resque_mailer
gem 'perform_later', git: 'git://github.com/KensoDev/perform_later.git' # should be after resque_mailer
gem 'russian', '~> 0.6.0'
gem 'highline', '~> 1.6.11'
gem 'state_machine'

View File

@ -1,3 +1,13 @@
GIT
remote: git://github.com/KensoDev/perform_later.git
revision: afd40794aa7101c8e73e9f105a064dd9bec47e31
specs:
perform_later (1.3.0)
rails (>= 3.0)
redis
resque (> 1.25)
resque-scheduler
GIT
remote: git://github.com/rosa-abf/grack.git
revision: 020be3fef3fb308b9d214252522aa5945bf6584a
@ -259,10 +269,6 @@ GEM
activesupport (>= 3.0.0)
cocaine (~> 0.4.0)
mime-types
perform_later (1.3.0)
rails (~> 3.0)
redis
resque
pg (0.14.1)
polyglot (0.3.3)
posix-spawn (0.3.8)
@ -307,7 +313,7 @@ GEM
rdoc (3.12.2)
json (~> 1.4)
redcarpet (2.2.2)
redis (3.0.6)
redis (3.0.7)
redis-actionpack (3.2.4)
actionpack (~> 3.2.0)
redis-rack (~> 1.4.4)
@ -335,6 +341,10 @@ GEM
redis-namespace (~> 1.2)
sinatra (>= 0.9.2)
vegas (~> 0.1.2)
resque-scheduler (2.5.1)
redis (>= 3.0.0)
resque (~> 1.25)
rufus-scheduler (~> 2.0)
resque-status (0.3.3)
redisk (>= 0.2.1)
resque (~> 1.19)
@ -364,6 +374,8 @@ GEM
rubypython (0.5.3)
blankslate (>= 2.1.2.3)
ffi (~> 1.0.7)
rufus-scheduler (2.0.24)
tzinfo (>= 0.3.22)
russian (0.6.0)
i18n (>= 0.5.0)
rvm-capistrano (1.5.1)
@ -493,7 +505,7 @@ DEPENDENCIES
omniauth-github
omniauth-google-oauth2
paperclip (~> 3.3.1)
perform_later (~> 1.3.0)
perform_later!
pg (~> 0.14.0)
puma
rack-throttle
@ -506,6 +518,7 @@ DEPENDENCIES
redhillonrails_core!
redis-rails
resque (~> 1.24)
resque-scheduler
resque-status (~> 0.3.3)
resque_mailer (~> 2.2)
rest-client (~> 1.6.6)

View File

@ -4,6 +4,7 @@
require File.expand_path('../config/application', __FILE__)
require 'rake'
require 'resque/tasks'
require 'resque_scheduler/tasks'
# This fixes connection fail with Postgres server on new fork:
task "resque:setup" => :environment do

View File

@ -16,6 +16,7 @@ class Api::V1::JobsController < Api::V1::BaseController
if current_user.system?
if task = (Resque.pop('rpm_worker_default') || Resque.pop('rpm_worker'))
@build_list = BuildList.where(id: task['args'][0]['id']).first
@build_list.delayed_add_job_to_abf_worker_queue
end
end

View File

@ -258,7 +258,6 @@ class BuildList < ActiveRecord::Base
later :publish, queue: :clone_build
later :add_job_to_abf_worker_queue, queue: :clone_build
HUMAN_CONTAINER_STATUSES = { WAITING_FOR_RESPONSE => :waiting_for_publish,
BUILD_PUBLISHED => :container_published,
BUILD_PUBLISH => :container_publish,
@ -524,6 +523,11 @@ class BuildList < ActiveRecord::Base
)
end
def delayed_add_job_to_abf_worker_queue
now_add_job_to_abf_worker_queue if status == BUILD_PENDING
end
later :delayed_add_job_to_abf_worker_queue, delay: 60, queue: :clone_build
protected
def create_container

View File

@ -1,5 +1,7 @@
require 'resque/server'
require 'resque/status_server'
require 'resque_scheduler'
require 'resque_scheduler/server'
::ResqueServer = ::Resque::Server # need for CanCan

View File

@ -3,15 +3,18 @@ Capistrano::Configuration.instance(:must_exist).load do
namespace :resque do
task :start do
start_workers
invoke "resque:scheduler:start"
end
task :stop do
stop_workers
invoke "resque:scheduler:stop"
end
task :restart do
stop_workers
start_workers
invoke "resque:scheduler:restart"
end
def rails_env
@ -36,5 +39,41 @@ Capistrano::Configuration.instance(:must_exist).load do
].join(',')
run "cd #{fetch :current_path} && COUNT=#{workers_count} QUEUE=#{queue} #{rails_env} BACKGROUND=yes bundle exec rake resque:workers"
end
def remote_file_exists?(full_path)
'true' == capture("if [ -e #{full_path} ]; then echo 'true'; fi").strip
end
namespace :scheduler do
desc "See current scheduler status"
task :status do
pid = "#{fetch :current_path}/tmp/pids/scheduler.pid"
if remote_file_exists?(pid)
info capture(:ps, "-f -p $(cat #{pid}) | sed -n 2p")
end
end
desc "Starts resque scheduler with default configs"
task :start do
pid = "#{fetch :current_path}/tmp/pids/scheduler.pid"
run "cd #{fetch :current_path} && #{rails_env} PIDFILE=#{pid} BACKGROUND=yes VERBOSE=1 MUTE=1 bundle exec rake resque:scheduler"
end
desc "Stops resque scheduler"
task :stop do
pid = "#{fetch :current_path}/tmp/pids/scheduler.pid"
if remote_file_exists?(pid)
run "cd #{fetch :current_path} && kill -s QUIT $(cat #{pid}); rm #{pid}"
end
end
task :restart do
invoke "resque:scheduler:stop"
invoke "resque:scheduler:start"
end
end
end
end